/// <summary> /// Adds and configures an ASP.NET Core web application. /// </summary> /// <param name="builder">The <see cref="IHostBuilder"/> to add the <see cref="IWebHostBuilder"/> to.</param> /// <param name="configure">The delegate that configures the <see cref="IWebHostBuilder"/>.</param> /// <param name="configureWebHostBuilder">The delegate that configures the <see cref="WebHostBuilderOptions"/>.</param> /// <returns>The <see cref="IHostBuilder"/>.</returns> public static IHostBuilder ConfigureWebHost(this IHostBuilder builder, Action <IWebHostBuilder> configure, Action <WebHostBuilderOptions> configureWebHostBuilder) { if (configure is null) { throw new ArgumentNullException(nameof(configure)); } if (configureWebHostBuilder is null) { throw new ArgumentNullException(nameof(configureWebHostBuilder)); } // Light up custom implementations namely ConfigureHostBuilder which throws. if (builder is ISupportsConfigureWebHost supportsConfigureWebHost) { return(supportsConfigureWebHost.ConfigureWebHost(configure, configureWebHostBuilder)); } var webHostBuilderOptions = new WebHostBuilderOptions(); configureWebHostBuilder(webHostBuilderOptions); var webhostBuilder = new GenericWebHostBuilder(builder, webHostBuilderOptions); configure(webhostBuilder); builder.ConfigureServices((context, services) => services.AddHostedService <GenericWebHostService>()); return(builder); }
/// <summary> /// Adds and configures an ASP.NET Core web application. /// </summary> public static IHostBuilder ConfigureWebHost(this IHostBuilder builder, Action <IWebHostBuilder> configure, Action <WebHostBuilderOptions> configureWebHostBuilder) { if (configure is null) { throw new ArgumentNullException(nameof(configure)); } if (configureWebHostBuilder is null) { throw new ArgumentNullException(nameof(configureWebHostBuilder)); } var webHostBuilderOptions = new WebHostBuilderOptions(); configureWebHostBuilder(webHostBuilderOptions); var webhostBuilder = new GenericWebHostBuilder(builder, webHostBuilderOptions); configure(webhostBuilder); builder.ConfigureServices((context, services) => services.AddHostedService <GenericWebHostService>()); return(builder); }