From 23512f940c7121a7f7951599b8ffdd502263bb66 Mon Sep 17 00:00:00 2001 From: Dave Tillman Date: Tue, 22 Nov 2016 10:48:09 -0700 Subject: [PATCH] Move ConfigureOptions to CreateClient --- .../DiscoveryClientFactory.cs | 6 ++++-- .../DiscoveryClientFactoryTest.cs | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Steeltoe.Discovery.Client/DiscoveryClientFactory.cs b/src/Steeltoe.Discovery.Client/DiscoveryClientFactory.cs index 8b085d6..a780f10 100644 --- a/src/Steeltoe.Discovery.Client/DiscoveryClientFactory.cs +++ b/src/Steeltoe.Discovery.Client/DiscoveryClientFactory.cs @@ -44,8 +44,6 @@ internal protected virtual object Create(IServiceProvider provider) return null; } - ConfigureOptions(); - var logFactory = provider.GetService(typeof(ILoggerFactory)) as ILoggerFactory; var lifeCycle = provider.GetService(typeof(IApplicationLifetime)) as IApplicationLifetime; @@ -54,7 +52,11 @@ internal protected virtual object Create(IServiceProvider provider) public virtual object CreateClient(IApplicationLifetime lifeCycle = null, ILoggerFactory logFactory = null) { + var logger = logFactory?.CreateLogger(); + + ConfigureOptions(); + if (_config == null) { logger?.LogWarning("Failed to create DiscoveryClient, no DiscoveryOptions"); diff --git a/test/Steeltoe.Discovery.Client.Test/DiscoveryClientFactoryTest.cs b/test/Steeltoe.Discovery.Client.Test/DiscoveryClientFactoryTest.cs index c3a61d8..18034d4 100644 --- a/test/Steeltoe.Discovery.Client.Test/DiscoveryClientFactoryTest.cs +++ b/test/Steeltoe.Discovery.Client.Test/DiscoveryClientFactoryTest.cs @@ -63,6 +63,16 @@ public void CreateClient_ClientTypeEureka_CreatesClient() Assert.IsType(typeof(EurekaDiscoveryClient), client); } + [Fact] + public void CreateClient_Calls_ConfigureOptions() + { + MyDiscoveryClientFactory factory = new MyDiscoveryClientFactory(); + IServiceProvider provider = new MyServiceProvier(); + IDiscoveryClient result = factory.CreateClient() as IDiscoveryClient; + Assert.NotNull(result); + Assert.True(factory.ConfigureOptionsCalled); + } + [Fact] public void Create_NullIServiceProvider_ReturnsNull() { @@ -100,15 +110,6 @@ public void Create_MissingOptions_ReturnsUnknown() Assert.Equal("Unknown", result.Description); } - [Fact] - public void Create_Calls_ConfigureOptions() - { - MyDiscoveryClientFactory factory = new MyDiscoveryClientFactory(); - IServiceProvider provider = new MyServiceProvier(); - IDiscoveryClient result = factory.Create(provider) as IDiscoveryClient; - Assert.NotNull(result); - Assert.True(factory.ConfigureOptionsCalled); - } } class MyDiscoveryClientFactory : DiscoveryClientFactory {