Class ProgramFactory
- Namespace
- Codebelt.Bootstrapper.Console
- Assembly
- Codebelt.Bootstrapper.Console.dll
The default implementation of IProgramFactory.
public class ProgramFactory : IProgramFactory
- Inheritance
-
ProgramFactory
- Implements
Examples
The following example shows how ProgramFactory activates a derived MinimalConsoleProgram from the entry assembly. The factory is what UseBootstrapperProgram registers, so consumer code resolves IProgramFactory.Instance (and can cast the registered service to ProgramFactory to confirm the concrete type).
using System.Threading;
using System.Threading.Tasks;
using Codebelt.Bootstrapper.Console;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace ProgramFactoryDemo;
public class MyProgram : MinimalConsoleProgram
{
public override Task RunAsync(System.IServiceProvider serviceProvider, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
public static class Program
{
public static void Main()
{
var builder = Host.CreateApplicationBuilder();
builder.UseBootstrapperProgram(typeof(MyProgram));
using var host = builder.Build();
var factory = (ProgramFactory)host.Services.GetRequiredService<IProgramFactory>();
var program = factory.Instance;
}
}
Constructors
ProgramFactory(Type)
Initializes a new instance of the ProgramFactory class.
public ProgramFactory(Type minimalConsoleProgramType)
Parameters
minimalConsoleProgramTypeType
Properties
Instance
Provides access to an instance inheriting from MinimalConsoleProgram.
public MinimalConsoleProgram Instance { get; }
Property Value
- MinimalConsoleProgram
A reference to the object of type MinimalConsoleProgram.