HostApplicationBuilderExtensions Class
Definition
- Namespace
- Codebelt.Bootstrapper.Console
- Assemblies
- 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
| Name | Description |
|---|---|
| UseBootstrapperProgram(IHostApplicationBuilder, Type) | Provides an implementation of a conventional based IProgramFactory. |
| UseMinimalConsoleProgram(IHostApplicationBuilder) | Provides an implementation of IHostedService that has the role of a console application. |