Codebelt

Codebelt.Bootstrapper.Web

Use WebProgram<TStartup>, WebStartup, or MinimalWebProgram to standardize ASP.NET Core host startup around the bootstrapper conventions.

.NET 10.0 MIT v5.1.1 7,899 downloads

Overview

Codebelt.Bootstrapper.Web adapts the core Codebelt.Bootstrapper abstractions to ASP.NET Core applications. It gives you two entry-point styles: WebProgram<TStartup> for the conventional Program and Startup pairing, and MinimalWebProgram for WebApplicationBuilder based apps.

The package is centered on WebStartup, which keeps service registration on the inherited ConfigureServices(IServiceCollection) contract and adds a web-specific pipeline hook through ConfigurePipeline(IApplicationBuilder). That lets the ASP.NET Core startup convention call into a predictable extension point while the base program types apply the bootstrapper lifetime and local-development defaults.

Key APIs

WebProgram<TStartup> is the conventional entry point for web apps that still want a dedicated startup type. Its protected CreateHostBuilder(string[] args) method creates the default host, applies UseBootstrapperLifetime(), applies UseBootstrapperEnvironmentDefaults<TStartup>(), and registers TStartup through ConfigureWebHostDefaults with UseStartup<TStartup>().

MinimalWebProgram is the minimal-hosting counterpart for applications that prefer WebApplicationBuilder. Its protected CreateHostBuilder(string[] args) method returns a WebApplicationBuilder that already has the bootstrapper lifetime and environment defaults applied before you add services or build the app.

WebStartup is the ASP.NET Core startup base class in this package. It extends StartupRoot, carries the injected IConfiguration and IHostEnvironment into derived types, and works with the inherited ConfigureServices(IServiceCollection) contract for dependency registration.

WebStartup.ConfigurePipeline(IApplicationBuilder) is the package-specific extension point for HTTP middleware and endpoints. The public Configure(IApplicationBuilder) method delegates directly to it so UseStartup<TStartup>() can discover the conventional startup method without exposing a second customization model.

Basic usage

Use this pattern when you want to keep the conventional Program and Startup split in an ASP.NET Core application while still inheriting the bootstrapper host setup. It matters because the web package centralizes lifetime wiring and local-development defaults in the base program type so the derived startup can focus on service registration and pipeline composition.

using Codebelt.Bootstrapper;
using Codebelt.Bootstrapper.Web;
using Codebelt.Extensions.Xunit;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit;

namespace MyProject.Tests;

public class WebProgramUsageTest : Test
{
    public WebProgramUsageTest(ITestOutputHelper output) : base(output) { }
    [Fact]
    public void CreateHostBuilder_ShouldWireStartupAndBootstrapperLifetime()
    {
        using var host = DemoProgram.CreateHostBuilderAccessor([]).Build();
        var lifetime = host.Services.GetRequiredService<IHostLifetime>();
        TestOutput.WriteLine($"Program: {typeof(DemoProgram).Name}; Startup: {typeof(DemoStartup).Name}; Lifetime: {lifetime.GetType().Name}");
        Assert.IsType<BootstrapperLifetime>(lifetime);
    }
    public sealed class DemoProgram : WebProgram<DemoStartup>
    {
        public static IHostBuilder CreateHostBuilderAccessor(string[] args) => CreateHostBuilder(args);
    }
    public sealed class DemoStartup(IConfiguration configuration, IHostEnvironment environment) : WebStartup(configuration, environment)
    {
        public override void ConfigureServices(IServiceCollection services) { }
        public override void ConfigurePipeline(IApplicationBuilder app) { }
    }
}

Installation

dotnet add package Codebelt.Bootstrapper.Web

Usage guidance

Choose Codebelt.Bootstrapper.Web when you want ASP.NET Core applications to follow a repeatable Program and Startup or minimal-host pattern with bootstrapper lifetime handling and local-development configuration defaults already applied. If you only need the lower-level host builder extensions, use Codebelt.Bootstrapper directly, and if you prefer plain ASP.NET Core bootstrapping without these base classes, stay with the framework's built-in host setup.

Family packages