diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard.cs index b55073d2..19b9a15a 100644 --- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard.cs +++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace WireMock.Owin { @@ -34,5 +36,24 @@ namespace WireMock.Owin } } } + + internal static class IWebHostBuilderExtensions + { + internal static IWebHostBuilder ConfigureAppConfigurationUsingEnvironmentVariables(this IWebHostBuilder builder) + { + return builder.ConfigureAppConfiguration(config => + { + config.AddEnvironmentVariables(); + }); + } + + internal static IWebHostBuilder ConfigureKestrelServerOptions(this IWebHostBuilder builder) + { + return builder.ConfigureServices((context, services) => + { + services.Configure(context.Configuration.GetSection("Kestrel")); + }); + } + } } #endif \ No newline at end of file diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard13.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard13.cs index 06fef017..80798cb7 100644 --- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard13.cs +++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard13.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using WireMock.HttpsCertificate; namespace WireMock.Owin @@ -26,5 +28,22 @@ namespace WireMock.Owin } } } + + internal static class IWebHostBuilderExtensions + { + internal static IWebHostBuilder ConfigureAppConfigurationUsingEnvironmentVariables(this IWebHostBuilder builder) => builder; + + internal static IWebHostBuilder ConfigureKestrelServerOptions(this IWebHostBuilder builder) + { + var configuration = new ConfigurationBuilder() + .AddEnvironmentVariables() + .Build(); + + return builder.ConfigureServices(services => + { + services.Configure(configuration.GetSection("Kestrel")); + }); + } + } } #endif \ No newline at end of file diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs index 17b587bd..65183159 100644 --- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs +++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs @@ -58,6 +58,7 @@ namespace WireMock.Owin } _host = builder + .ConfigureAppConfigurationUsingEnvironmentVariables() .ConfigureServices(services => { services.AddSingleton(_options); @@ -81,6 +82,7 @@ namespace WireMock.Owin SetHttpsAndUrls(options, _urlOptions.GetDetails()); }) + .ConfigureKestrelServerOptions() #if NETSTANDARD1_3 .UseUrls(_urlOptions.GetDetails().Select(u => u.Url).ToArray())