Class HostApplicationBuilderExtensions
- Namespace
- Codebelt.Bootstrapper.Console
- Assembly
- Codebelt.Bootstrapper.Console.dll
Extension methods for the IHostApplicationBuilder.
public static class HostApplicationBuilderExtensions
- Inheritance
-
HostApplicationBuilderExtensions
Examples
The following example shows how to compose UseBootstrapperProgram and UseMinimalConsoleProgram on a HostApplicationBuilder to wire a MinimalConsoleProgram implementation into the host. The ProgramFactory then discovers the derived MinimalConsoleProgram in the entry assembly and the MinimalConsoleHostedService runs its RunAsync once the host is fully started.
using System;
using System.Threading;
using System.Threading.Tasks;
using Codebelt.Bootstrapper.Console;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace MinimalConsoleHostDemo;
public class MyProgram : MinimalConsoleProgram
{
public override Task RunAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
public static class Program
{
public static void Main()
{
var builder = Host.CreateApplicationBuilder();
builder.UseBootstrapperProgram(typeof(MyProgram));
builder.UseMinimalConsoleProgram();
using var host = builder.Build();
var hosted = host.Services.GetServices<IHostedService>();
}
}
Methods
UseBootstrapperProgram(IHostApplicationBuilder, Type)
Provides an implementation of a conventional based IProgramFactory.
public static IHostApplicationBuilder UseBootstrapperProgram(this IHostApplicationBuilder hostBuilder, Type minimalConsoleProgramType)
Parameters
hostBuilderIHostApplicationBuilderThe IHostApplicationBuilder to configure.
minimalConsoleProgramTypeTypeThe Type that must be assignable from MinimalConsoleProgram.
Returns
- IHostApplicationBuilder
The same instance of the IHostApplicationBuilder for chaining.
UseMinimalConsoleProgram(IHostApplicationBuilder)
Provides an implementation of IHostedService that has the role of a console application.
public static IHostApplicationBuilder UseMinimalConsoleProgram(this IHostApplicationBuilder hostBuilder)
Parameters
hostBuilderIHostApplicationBuilderThe IHostApplicationBuilder to configure.
Returns
- IHostApplicationBuilder
The same instance of the IHostApplicationBuilder for chaining.