Class WorkerProgram<TStartup>
- Namespace
- Codebelt.Bootstrapper.Worker
- Assembly
- Codebelt.Bootstrapper.Worker.dll
The entry point of an application responsible for registering its WorkerStartup partner.
public class WorkerProgram<TStartup> : ProgramRoot<TStartup> where TStartup : WorkerStartup
Type Parameters
TStartupThe type containing the startup methods for the application.
- Inheritance
-
ProgramRoot<TStartup>WorkerProgram<TStartup>
Examples
The following example shows how WorkerProgram<TStartup> is used as the base entry point for a conventional .NET worker service. The CreateHostBuilder helper composes UseBootstrapperLifetime, UseBootstrapperEnvironmentDefaults<TStartup>, and UseBootstrapperStartup<TStartup> so the resulting host wires the WorkerStartup partner through the standard bootstrapper convention. The example derives a Program : WorkerProgram<MyStartup> so the protected CreateHostBuilder is reachable, then builds the host and confirms the bootstrapper lifetime and the IStartupFactory<TStartup> registration before letting the host run.
using Codebelt.Bootstrapper;
using Codebelt.Bootstrapper.Worker;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace WorkerProgramDemo;
public class MyStartup : WorkerStartup
{
public MyStartup(IConfiguration configuration, IHostEnvironment environment) : base(configuration, environment)
{
}
public override void ConfigureServices(IServiceCollection services)
{
}
}
public class Program : WorkerProgram<MyStartup>
{
public static void Main(string[] args)
{
using var host = CreateHostBuilder(args).Build();
var lifetime = host.Services.GetRequiredService<IHostLifetime>();
var factory = host.Services.GetRequiredService<IStartupFactory<MyStartup>>();
host.Run();
}
}
Methods
CreateHostBuilder(string[])
Creates an IHostBuilder used to set up the host.
protected static IHostBuilder CreateHostBuilder(string[] args)
Parameters
argsstring[]The command line arguments.
Returns
- IHostBuilder
The initialized IHostBuilder.