Add overload for Configure that gets WebHostBuilderContext (#8697)
This commit is contained in:
parent
03357bf92b
commit
d24ec01224
|
|
@ -35,6 +35,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
public static partial class WebHostBuilderExtensions
|
public static partial class WebHostBuilderExtensions
|
||||||
{
|
{
|
||||||
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder Configure(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> configureApp) { throw null; }
|
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder Configure(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> configureApp) { throw null; }
|
||||||
|
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder Configure(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.AspNetCore.Builder.IApplicationBuilder> configureApp) { throw null; }
|
||||||
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureAppConfiguration(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Configuration.IConfigurationBuilder> configureDelegate) { throw null; }
|
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureAppConfiguration(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Configuration.IConfigurationBuilder> configureDelegate) { throw null; }
|
||||||
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureLogging(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; }
|
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureLogging(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; }
|
||||||
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureLogging(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; }
|
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureLogging(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; }
|
||||||
|
|
|
||||||
|
|
@ -303,13 +303,14 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
||||||
builder.Build(instance)(container);
|
builder.Build(instance)(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWebHostBuilder Configure(Action<IApplicationBuilder> configure)
|
public IWebHostBuilder Configure(Action<WebHostBuilderContext, IApplicationBuilder> configure)
|
||||||
{
|
{
|
||||||
_builder.ConfigureServices((context, services) =>
|
_builder.ConfigureServices((context, services) =>
|
||||||
{
|
{
|
||||||
services.Configure<GenericWebHostServiceOptions>(options =>
|
services.Configure<GenericWebHostServiceOptions>(options =>
|
||||||
{
|
{
|
||||||
options.ConfigureApplication = configure;
|
var webhostBuilderContext = GetWebHostBuilderContext(context);
|
||||||
|
options.ConfigureApplication = app => configure(webhostBuilderContext, app);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
||||||
return _builder.UseDefaultServiceProvider(configure);
|
return _builder.UseDefaultServiceProvider(configure);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWebHostBuilder Configure(Action<IApplicationBuilder> configure)
|
public IWebHostBuilder Configure(Action<WebHostBuilderContext, IApplicationBuilder> configure)
|
||||||
{
|
{
|
||||||
return _builder.Configure(configure);
|
return _builder.Configure(configure);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
||||||
{
|
{
|
||||||
internal interface ISupportsStartup
|
internal interface ISupportsStartup
|
||||||
{
|
{
|
||||||
IWebHostBuilder Configure(Action<IApplicationBuilder> configure);
|
IWebHostBuilder Configure(Action<WebHostBuilderContext, IApplicationBuilder> configure);
|
||||||
IWebHostBuilder UseStartup(Type startupType);
|
IWebHostBuilder UseStartup(Type startupType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,28 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
/// <param name="configureApp">The delegate that configures the <see cref="IApplicationBuilder"/>.</param>
|
/// <param name="configureApp">The delegate that configures the <see cref="IApplicationBuilder"/>.</param>
|
||||||
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
|
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
|
||||||
public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action<IApplicationBuilder> configureApp)
|
public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action<IApplicationBuilder> configureApp)
|
||||||
|
{
|
||||||
|
return hostBuilder.Configure((_, app) => configureApp(app), configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specify the startup method to be used to configure the web application.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to configure.</param>
|
||||||
|
/// <param name="configureApp">The delegate that configures the <see cref="IApplicationBuilder"/>.</param>
|
||||||
|
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
|
||||||
|
public static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, IApplicationBuilder> configureApp)
|
||||||
|
{
|
||||||
|
return hostBuilder.Configure(configureApp, configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IWebHostBuilder Configure(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, IApplicationBuilder> configureApp, string startupAssemblyName)
|
||||||
{
|
{
|
||||||
if (configureApp == null)
|
if (configureApp == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(configureApp));
|
throw new ArgumentNullException(nameof(configureApp));
|
||||||
}
|
}
|
||||||
|
|
||||||
var startupAssemblyName = configureApp.GetMethodInfo().DeclaringType.GetTypeInfo().Assembly.GetName().Name;
|
|
||||||
|
|
||||||
hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName);
|
hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName);
|
||||||
|
|
||||||
// Light up the ISupportsStartup implementation
|
// Light up the ISupportsStartup implementation
|
||||||
|
|
@ -38,11 +52,11 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
return supportsStartup.Configure(configureApp);
|
return supportsStartup.Configure(configureApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hostBuilder.ConfigureServices(services =>
|
return hostBuilder.ConfigureServices((context, services) =>
|
||||||
{
|
{
|
||||||
services.AddSingleton<IStartup>(sp =>
|
services.AddSingleton<IStartup>(sp =>
|
||||||
{
|
{
|
||||||
return new DelegateStartup(sp.GetRequiredService<IServiceProviderFactory<IServiceCollection>>(), configureApp);
|
return new DelegateStartup(sp.GetRequiredService<IServiceProviderFactory<IServiceCollection>>(), (app => configureApp(context, app)));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests.Fakes
|
||||||
return new GenericWebHost(_hostBuilder.Build());
|
return new GenericWebHost(_hostBuilder.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWebHostBuilder Configure(Action<IApplicationBuilder> configure)
|
public IWebHostBuilder Configure(Action<WebHostBuilderContext, IApplicationBuilder> configure)
|
||||||
{
|
{
|
||||||
_builder.Configure(configure);
|
_builder.Configure(configure);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue