diff --git a/src/Ocelot.Library/Infrastructure/Services/IRequestDataService.cs b/src/Ocelot.Library/Infrastructure/Services/IScopedRequestDataRepository.cs similarity index 79% rename from src/Ocelot.Library/Infrastructure/Services/IRequestDataService.cs rename to src/Ocelot.Library/Infrastructure/Services/IScopedRequestDataRepository.cs index 5af72678..cb5e60a9 100644 --- a/src/Ocelot.Library/Infrastructure/Services/IRequestDataService.cs +++ b/src/Ocelot.Library/Infrastructure/Services/IScopedRequestDataRepository.cs @@ -2,7 +2,7 @@ using Ocelot.Library.Infrastructure.Responses; namespace Ocelot.Library.Infrastructure.Services { - public interface IRequestDataService + public interface IScopedRequestDataRepository { Response Add(string key, T value); Response Get(string key); diff --git a/src/Ocelot.Library/Infrastructure/Services/RequestDataService.cs b/src/Ocelot.Library/Infrastructure/Services/ScopedRequestDataRepository.cs similarity index 89% rename from src/Ocelot.Library/Infrastructure/Services/RequestDataService.cs rename to src/Ocelot.Library/Infrastructure/Services/ScopedRequestDataRepository.cs index 28cd07e3..71d94659 100644 --- a/src/Ocelot.Library/Infrastructure/Services/RequestDataService.cs +++ b/src/Ocelot.Library/Infrastructure/Services/ScopedRequestDataRepository.cs @@ -5,11 +5,11 @@ using Ocelot.Library.Infrastructure.Responses; namespace Ocelot.Library.Infrastructure.Services { - public class RequestDataService : IRequestDataService + public class ScopedRequestDataRepository : IScopedRequestDataRepository { private readonly IHttpContextAccessor _httpContextAccessor; - public RequestDataService(IHttpContextAccessor httpContextAccessor) + public ScopedRequestDataRepository(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; } diff --git a/src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddleware.cs index 1b17c124..28afbfe1 100644 --- a/src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddleware.cs +++ b/src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddleware.cs @@ -11,17 +11,17 @@ namespace Ocelot.Library.Middleware private readonly RequestDelegate _next; private readonly IDownstreamRouteFinder _downstreamRouteFinder; private readonly IHttpResponder _responder; - private readonly IRequestDataService _requestDataService; + private readonly IScopedRequestDataRepository _scopedRequestDataRepository; public DownstreamRouteFinderMiddleware(RequestDelegate next, IDownstreamRouteFinder downstreamRouteFinder, IHttpResponder responder, - IRequestDataService requestDataService) + IScopedRequestDataRepository scopedRequestDataRepository) { _next = next; _downstreamRouteFinder = downstreamRouteFinder; _responder = responder; - _requestDataService = requestDataService; + _scopedRequestDataRepository = scopedRequestDataRepository; } public async Task Invoke(HttpContext context) @@ -36,7 +36,7 @@ namespace Ocelot.Library.Middleware return; } - _requestDataService.Add("DownstreamRoute", downstreamRoute.Data); + _scopedRequestDataRepository.Add("DownstreamRoute", downstreamRoute.Data); await _next.Invoke(context); } diff --git a/src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddleware.cs b/src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddleware.cs index b8e04ef7..d69ae887 100644 --- a/src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddleware.cs +++ b/src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddleware.cs @@ -11,23 +11,23 @@ namespace Ocelot.Library.Middleware { private readonly RequestDelegate _next; private readonly IDownstreamUrlTemplateVariableReplacer _urlReplacer; - private readonly IRequestDataService _requestDataService; + private readonly IScopedRequestDataRepository _scopedRequestDataRepository; private readonly IHttpResponder _responder; public DownstreamUrlCreatorMiddleware(RequestDelegate next, IDownstreamUrlTemplateVariableReplacer urlReplacer, - IRequestDataService requestDataService, + IScopedRequestDataRepository scopedRequestDataRepository, IHttpResponder responder) { _next = next; _urlReplacer = urlReplacer; - _requestDataService = requestDataService; + _scopedRequestDataRepository = scopedRequestDataRepository; _responder = responder; } public async Task Invoke(HttpContext context) { - var downstreamRoute = _requestDataService.Get("DownstreamRoute"); + var downstreamRoute = _scopedRequestDataRepository.Get("DownstreamRoute"); if (downstreamRoute.IsError) { @@ -37,7 +37,7 @@ namespace Ocelot.Library.Middleware var downstreamUrl = _urlReplacer.ReplaceTemplateVariables(downstreamRoute.Data); - _requestDataService.Add("DownstreamUrl", downstreamUrl); + _scopedRequestDataRepository.Add("DownstreamUrl", downstreamUrl); await _next.Invoke(context); } diff --git a/src/Ocelot.Library/Middleware/HttpRequesterMiddleware.cs b/src/Ocelot.Library/Middleware/HttpRequesterMiddleware.cs index f564bca1..b154276f 100644 --- a/src/Ocelot.Library/Middleware/HttpRequesterMiddleware.cs +++ b/src/Ocelot.Library/Middleware/HttpRequesterMiddleware.cs @@ -11,22 +11,22 @@ namespace Ocelot.Library.Middleware private readonly RequestDelegate _next; private readonly IHttpRequester _requester; private readonly IHttpResponder _responder; - private readonly IRequestDataService _requestDataService; + private readonly IScopedRequestDataRepository _scopedRequestDataRepository; public HttpRequesterMiddleware(RequestDelegate next, IHttpRequester requester, IHttpResponder responder, - IRequestDataService requestDataService) + IScopedRequestDataRepository scopedRequestDataRepository) { _next = next; _requester = requester; _responder = responder; - _requestDataService = requestDataService; + _scopedRequestDataRepository = scopedRequestDataRepository; } public async Task Invoke(HttpContext context) { - var downstreamUrl = _requestDataService.Get("DownstreamUrl"); + var downstreamUrl = _scopedRequestDataRepository.Get("DownstreamUrl"); if (downstreamUrl.IsError) { diff --git a/src/Ocelot/Startup.cs b/src/Ocelot/Startup.cs index bd592588..7645a3db 100644 --- a/src/Ocelot/Startup.cs +++ b/src/Ocelot/Startup.cs @@ -47,7 +47,7 @@ namespace Ocelot // see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc services.AddSingleton(); - services.AddScoped(); + services.AddScoped(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/test/Ocelot.UnitTests/Services/RequestDataServiceTests.cs b/test/Ocelot.UnitTests/Services/ScopedRequestDataRepositoryTests.cs similarity index 79% rename from test/Ocelot.UnitTests/Services/RequestDataServiceTests.cs rename to test/Ocelot.UnitTests/Services/ScopedRequestDataRepositoryTests.cs index 84921c34..4b07437e 100644 --- a/test/Ocelot.UnitTests/Services/RequestDataServiceTests.cs +++ b/test/Ocelot.UnitTests/Services/ScopedRequestDataRepositoryTests.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Moq; +using Microsoft.AspNetCore.Http; using Ocelot.Library.Infrastructure.Responses; using Ocelot.Library.Infrastructure.Services; using Shouldly; @@ -12,19 +7,19 @@ using Xunit; namespace Ocelot.UnitTests.Services { - public class RequestDataServiceTests + public class ScopedRequestDataRepositoryTests { - private IRequestDataService _requestDataService; + private IScopedRequestDataRepository _scopedRequestDataRepository; private IHttpContextAccessor _httpContextAccesor; private string _key; private object _toAdd; private Response _result; - public RequestDataServiceTests() + public ScopedRequestDataRepositoryTests() { _httpContextAccesor = new HttpContextAccessor(); _httpContextAccesor.HttpContext = new DefaultHttpContext(); - _requestDataService = new RequestDataService(_httpContextAccesor); + _scopedRequestDataRepository = new ScopedRequestDataRepository(_httpContextAccesor); } [Fact] @@ -53,7 +48,7 @@ namespace Ocelot.UnitTests.Services private void WhenIGetTheItem() { - _result = _requestDataService.Get(_key); + _result = _scopedRequestDataRepository.Get(_key); } private void GivenThereIsAnItemInTheContext(string key) @@ -71,7 +66,7 @@ namespace Ocelot.UnitTests.Services private void WhenIAddTheItem() { - _requestDataService.Add(_key, _toAdd); + _scopedRequestDataRepository.Add(_key, _toAdd); } private void ThenTheItemIsAdded()