mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 20:10:50 +08:00 
			
		
		
		
	Add ConfigAwarePlaceholders class (#997)
* Add ConfigAwarePlaceholders class This allows placeholder values to be sourced from IConfiguration in addition to set values. * Rework how IPlaceholders is decorated in container
This commit is contained in:
		
				
					committed by
					
						
						Thiago Loureiro
					
				
			
			
				
	
			
			
			
						parent
						
							b6f3f0f28a
						
					
				
				
					commit
					bef40041ba
				
			@@ -14,6 +14,7 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Linq;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using Ocelot.Infrastructure;
 | 
			
		||||
    using TestStack.BDDfy;
 | 
			
		||||
    using Xunit;
 | 
			
		||||
    using static Ocelot.UnitTests.Middleware.UserDefinedResponseAggregatorTests;
 | 
			
		||||
@@ -136,6 +137,16 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_replace_iplaceholder()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(x => x.WhenISetUpOcelotServices())
 | 
			
		||||
                .When(x => AddConfigPlaceholders())
 | 
			
		||||
                .Then(x => ThenAnExceptionIsntThrown())
 | 
			
		||||
                .And(x => ThenTheIPlaceholderInstanceIsReplaced())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AddSingletonDefinedAggregator<T>()
 | 
			
		||||
            where T : class, IDefinedAggregator
 | 
			
		||||
        {
 | 
			
		||||
@@ -148,6 +159,11 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
            _ocelotBuilder.AddTransientDefinedAggregator<T>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AddConfigPlaceholders()
 | 
			
		||||
        {
 | 
			
		||||
            _ocelotBuilder.AddConfigPlaceholders();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheSpecificHandlersAreTransient()
 | 
			
		||||
        {
 | 
			
		||||
            var handlers = _serviceProvider.GetServices<DelegatingHandler>().ToList();
 | 
			
		||||
@@ -235,6 +251,13 @@ namespace Ocelot.UnitTests.DependencyInjection
 | 
			
		||||
            _ocelotBuilder.ShouldBeOfType<OcelotBuilder>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheIPlaceholderInstanceIsReplaced()
 | 
			
		||||
        {
 | 
			
		||||
            _serviceProvider = _services.BuildServiceProvider();
 | 
			
		||||
            var placeholders = _serviceProvider.GetService<IPlaceholders>();
 | 
			
		||||
            placeholders.ShouldBeOfType<ConfigAwarePlaceholders>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void WhenISetUpOcelotServices()
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user