mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
removed null admin path hack (#513)
This commit is contained in:
parent
049731b43b
commit
29ff0045fe
@ -10,6 +10,7 @@ using Ocelot.Configuration.Validator;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Responses;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Ocelot.Configuration.Creator
|
||||
{
|
||||
@ -49,14 +50,14 @@ namespace Ocelot.Configuration.Creator
|
||||
IRateLimitOptionsCreator rateLimitOptionsCreator,
|
||||
IRegionCreator regionCreator,
|
||||
IHttpHandlerOptionsCreator httpHandlerOptionsCreator,
|
||||
IAdministrationPath adminPath,
|
||||
IServiceProvider serviceProvider,
|
||||
IHeaderFindAndReplaceCreator headerFAndRCreator,
|
||||
IDownstreamAddressesCreator downstreamAddressesCreator
|
||||
)
|
||||
{
|
||||
_downstreamAddressesCreator = downstreamAddressesCreator;
|
||||
_headerFAndRCreator = headerFAndRCreator;
|
||||
_adminPath = adminPath;
|
||||
_adminPath = serviceProvider.GetService<IAdministrationPath>();
|
||||
_regionCreator = regionCreator;
|
||||
_rateLimitOptionsCreator = rateLimitOptionsCreator;
|
||||
_requestIdKeyCreator = requestIdKeyCreator;
|
||||
@ -117,8 +118,10 @@ namespace Ocelot.Configuration.Creator
|
||||
|
||||
var httpHandlerOptions = _httpHandlerOptionsCreator.Create(fileConfiguration.GlobalConfiguration.HttpHandlerOptions);
|
||||
|
||||
var adminPath = _adminPath != null ? _adminPath.Path : null;
|
||||
|
||||
var config = new InternalConfiguration(reRoutes,
|
||||
_adminPath.Path,
|
||||
adminPath,
|
||||
serviceProviderConfiguration,
|
||||
fileConfiguration.GlobalConfiguration.RequestIdKey,
|
||||
lbOptions,
|
||||
|
@ -1,12 +0,0 @@
|
||||
namespace Ocelot.DependencyInjection
|
||||
{
|
||||
public class NullAdministrationPath : IAdministrationPath
|
||||
{
|
||||
public NullAdministrationPath()
|
||||
{
|
||||
Path = null;
|
||||
}
|
||||
|
||||
public string Path {get;private set;}
|
||||
}
|
||||
}
|
@ -152,12 +152,10 @@ namespace Ocelot.DependencyInjection
|
||||
_services.AddLogging();
|
||||
_services.AddMiddlewareAnalysis();
|
||||
_services.AddWebEncoders();
|
||||
_services.AddSingleton<IAdministrationPath>(new NullAdministrationPath());
|
||||
|
||||
_services.TryAddSingleton<IMultiplexer, Multiplexer>();
|
||||
_services.TryAddSingleton<IResponseAggregator, SimpleJsonResponseAggregator>();
|
||||
_services.AddSingleton<ITracingHandlerFactory, TracingHandlerFactory>();
|
||||
|
||||
_services.TryAddSingleton<IFileConfigurationPollerOptions, InMemoryFileConfigurationPollerOptions>();
|
||||
_services.TryAddSingleton<IAddHeadersToResponse, AddHeadersToResponse>();
|
||||
_services.TryAddSingleton<IPlaceholders, Placeholders>();
|
||||
@ -180,8 +178,7 @@ namespace Ocelot.DependencyInjection
|
||||
AddIdentityServer(identityServerConfiguration, administrationPath);
|
||||
}
|
||||
|
||||
var descriptor = new ServiceDescriptor(typeof(IAdministrationPath), administrationPath);
|
||||
_services.Replace(descriptor);
|
||||
_services.AddSingleton<IAdministrationPath>(administrationPath);
|
||||
return new OcelotAdministrationBuilder(_services, _configurationRoot);
|
||||
}
|
||||
|
||||
@ -194,9 +191,7 @@ namespace Ocelot.DependencyInjection
|
||||
AddIdentityServer(configureOptions);
|
||||
}
|
||||
|
||||
//todo - hack because we add this earlier so it always exists for some reason...investigate..
|
||||
var descriptor = new ServiceDescriptor(typeof(IAdministrationPath), administrationPath);
|
||||
_services.Replace(descriptor);
|
||||
_services.AddSingleton<IAdministrationPath>(administrationPath);
|
||||
return new OcelotAdministrationBuilder(_services, _configurationRoot);
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@
|
||||
|
||||
private static bool AdministrationApiInUse(IAdministrationPath adminPath)
|
||||
{
|
||||
return adminPath.GetType() != typeof(NullAdministrationPath);
|
||||
return adminPath != null;
|
||||
}
|
||||
|
||||
private static async Task SetFileConfigInConsul(IApplicationBuilder builder,
|
||||
|
@ -36,7 +36,7 @@
|
||||
private readonly Mock<IRateLimitOptionsCreator> _rateLimitOptions;
|
||||
private readonly Mock<IRegionCreator> _regionCreator;
|
||||
private readonly Mock<IHttpHandlerOptionsCreator> _httpHandlerOptionsCreator;
|
||||
private readonly Mock<IAdministrationPath> _adminPath;
|
||||
private readonly Mock<IServiceProvider> _serviceProvider;
|
||||
private readonly Mock<IHeaderFindAndReplaceCreator> _headerFindAndReplaceCreator;
|
||||
private readonly Mock<IDownstreamAddressesCreator> _downstreamAddressesCreator;
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
_rateLimitOptions = new Mock<IRateLimitOptionsCreator>();
|
||||
_regionCreator = new Mock<IRegionCreator>();
|
||||
_httpHandlerOptionsCreator = new Mock<IHttpHandlerOptionsCreator>();
|
||||
_adminPath = new Mock<IAdministrationPath>();
|
||||
_serviceProvider = new Mock<IServiceProvider>();
|
||||
_headerFindAndReplaceCreator = new Mock<IHeaderFindAndReplaceCreator>();
|
||||
_downstreamAddressesCreator = new Mock<IDownstreamAddressesCreator>();
|
||||
|
||||
@ -71,7 +71,7 @@
|
||||
_rateLimitOptions.Object,
|
||||
_regionCreator.Object,
|
||||
_httpHandlerOptionsCreator.Object,
|
||||
_adminPath.Object,
|
||||
_serviceProvider.Object,
|
||||
_headerFindAndReplaceCreator.Object,
|
||||
_downstreamAddressesCreator.Object);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user