Table of Contents

HostApplicationBuilderExtensions Class

Definition

Namespace
Codebelt.Bootstrapper
Assemblies
Codebelt.Bootstrapper.dll
Source
src/Codebelt.Bootstrapper/HostApplicationBuilderExtensions.cs

Extension methods for the IHostApplicationBuilder.

public static class HostApplicationBuilderExtensions
Inheritance
HostApplicationBuilderExtensions

Examples

The following example shows how to install BootstrapperLifetime and apply local-development environment defaults on a minimal-host HostApplicationBuilder so that user secrets from the application assembly are added to configuration when the environment is LocalDevelopment.

using Codebelt.Bootstrapper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace HostApplicationBuilderExtensionsDemo;

public static class Program
{
    public static void Main()
    {
        var builder = Host.CreateApplicationBuilder();
        builder.UseBootstrapperLifetime();
        builder.UseBootstrapperEnvironmentDefaults();

        var host = builder.Build();
        host.Start();

        var lifetime = host.Services.GetRequiredService<IHostLifetime>();
    }
}

Methods

Name Description
UseBootstrapperEnvironmentDefaults(IHostApplicationBuilder)

Adds conventional environment defaults for local development.

UseBootstrapperLifetime(IHostApplicationBuilder)

Listens for Ctrl+C or SIGTERM and calls StopApplication() to start the shutdown process.