Table of Contents

Class HostApplicationBuilderExtensions

Namespace
Codebelt.Bootstrapper
Assembly
Codebelt.Bootstrapper.dll

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

UseBootstrapperEnvironmentDefaults(IHostApplicationBuilder)

Adds conventional environment defaults for local development.

public static IHostApplicationBuilder UseBootstrapperEnvironmentDefaults(this IHostApplicationBuilder hostBuilder)

Parameters

hostBuilder IHostApplicationBuilder

The IHostApplicationBuilder to configure.

Returns

IHostApplicationBuilder

The same instance of the IHostApplicationBuilder for chaining.

Remarks

When the current environment is local development, this method attempts to resolve the application assembly from ApplicationName and adds user secrets to IConfigurationBuilder. If the application assembly cannot be resolved, the operation is ignored.

UseBootstrapperLifetime(IHostApplicationBuilder)

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

public static IHostApplicationBuilder UseBootstrapperLifetime(this IHostApplicationBuilder hostBuilder)

Parameters

hostBuilder IHostApplicationBuilder

The IHostApplicationBuilder to configure.

Returns

IHostApplicationBuilder

The same instance of the IHostApplicationBuilder for chaining.

Remarks

Complements the default implementation of ConsoleLifetime.