Class WebAppBuilderExtensions
Provides extension methods for WebApplicationBuilder to configure, build, and optionally run a WebApplication.
Inherited Members
Namespace: Coree.NETASP.Extensions.WebApplicationBuilderExtensions
Assembly: Coree.NETASP.dll
Syntax
public static class WebAppBuilderExtensions
Methods
| Edit this page View SourceSetupAndBuild(WebApplicationBuilder, Action<WebApplicationBuilder?, WebApplication?>)
Configures and builds a WebApplication using the specified configuration actions. This method centralizes the setup for various components of a web application, helping to keep the configuration clean and uncluttered.
The WebApplicationBuilder to configure. An action to configure both the builder and the application. This unified approach allows for keeping related configurations together, simplifying the overall setup process.var app = WebApplication.CreateBuilder(args).SetupAndBuild((builderStage, appStage) => {
// Configure the services for controllers.
if (builderStage != null)
{
builderStage.Services.AddControllers();
}
// Map controller routes.
if (appStage != null)
{
appStage.MapControllers();
}
// Configure the services for Razor Pages.
builderStage?.Services.AddRazorPages();
// Map Razor Page routes.
appStage?.MapRazorPages();
});
app.Run();
Declaration
public static WebApplication SetupAndBuild(this WebApplicationBuilder builder, Action<WebApplicationBuilder?, WebApplication?> configure)
Parameters
Type | Name | Description |
---|---|---|
WebApplicationBuilder | builder | |
Action<WebApplicationBuilder, WebApplication> | configure |
Returns
Type | Description |
---|---|
WebApplication |
SetupAndBuildRun(WebApplicationBuilder, Action<WebApplicationBuilder?, WebApplication?>)
Configures, builds, and runs a WebApplication synchronously using the specified configuration actions.
Declaration
public static void SetupAndBuildRun(this WebApplicationBuilder builder, Action<WebApplicationBuilder?, WebApplication?> configure)
Parameters
Type | Name | Description |
---|---|---|
WebApplicationBuilder | builder | The WebApplicationBuilder to configure. |
Action<WebApplicationBuilder, WebApplication> | configure | An action to configure both the builder and the application. |
SetupAndBuildRunAsync(WebApplicationBuilder, Action<WebApplicationBuilder?, WebApplication?>)
Configures, builds, and runs a WebApplication asynchronously using the specified configuration actions.
Declaration
public static Task SetupAndBuildRunAsync(this WebApplicationBuilder builder, Action<WebApplicationBuilder?, WebApplication?> configure)
Parameters
Type | Name | Description |
---|---|---|
WebApplicationBuilder | builder | The WebApplicationBuilder to configure. |
Action<WebApplicationBuilder, WebApplication> | configure | An action to configure both the builder and the application. |
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation of building and running the application. |