mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
renamed from service to repository, makes more sense i guess
This commit is contained in:
parent
229c0878ed
commit
f505fd6e90
@ -2,7 +2,7 @@ using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Services
|
||||
{
|
||||
public interface IRequestDataService
|
||||
public interface IScopedRequestDataRepository
|
||||
{
|
||||
Response Add<T>(string key, T value);
|
||||
Response<T> Get<T>(string key);
|
@ -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;
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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>("DownstreamRoute");
|
||||
var downstreamRoute = _scopedRequestDataRepository.Get<DownstreamRoute>("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);
|
||||
}
|
||||
|
@ -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<string>("DownstreamUrl");
|
||||
var downstreamUrl = _scopedRequestDataRepository.Get<string>("DownstreamUrl");
|
||||
|
||||
if (downstreamUrl.IsError)
|
||||
{
|
||||
|
@ -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<IHttpContextAccessor, HttpContextAccessor>();
|
||||
services.AddScoped<IRequestDataService, RequestDataService>();
|
||||
services.AddScoped<IScopedRequestDataRepository, ScopedRequestDataRepository>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
@ -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<int[]> _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<int[]>(_key);
|
||||
_result = _scopedRequestDataRepository.Get<int[]>(_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()
|
Loading…
x
Reference in New Issue
Block a user