Class HostExtensions
Provides extension methods for configuring and integrating Atom services into a .NET host.
public static class HostExtensions
- Inheritance
-
objectHostExtensions
Remarks
This class simplifies the setup of an Atom application by registering essential services, logging providers, and dependencies required for the Atom framework to function correctly.
Methods
AddAtom<TBuilder, TBuild>(TBuilder, string[])
Configures the Microsoft.Extensions.Hosting.IHostApplicationBuilder with all necessary Atom services, dependencies, logging, and default settings.
public static TBuilder AddAtom<TBuilder, TBuild>(this TBuilder builder, string[] args) where TBuilder : IHostApplicationBuilder where TBuild : BuildDefinition, IConfigureHost
Parameters
builderTBuilderThe host application builder instance to configure.
argsstring[]The command-line arguments provided to the application.
Returns
- TBuilder
The configured host application builder instance.
Type Parameters
TBuilderThe type of the host application builder.
TBuildThe type of the build definition, which must derive from BuildDefinition and implement IConfigureHost. Classes generated for BuildDefinitionAttribute do both.
Remarks
This method performs the following key configurations:
- Registers the Invex.Atom.Build.AtomService as a hosted service.
- Registers the build definition (
TBuild) and related interfaces. - Adds core Atom services like IParamService, IReportService, and Spectre.Console.IAnsiConsole.
- Registers default providers for build information: IBuildIdProvider, IBuildVersionProvider, and IBuildTimestampProvider.
- Configures file system access via Invex.FileSystem.IRootedFileSystem.
- Registers build execution and workflow generation services.
- Sets up logging with Spectre.Console and report providers, filtering out verbose Microsoft host logs.
- Parses command-line arguments and makes them available as CommandLineArgs.
- Resolves and registers the BuildModel.
-
Invokes the static ConfigureHostBuilder(IHostApplicationBuilder) of
TBuild, without constructing the build definition, and records ConfigureHost(IHost) for UseAtom(IHost) to call.
UseAtom(IHost)
Configures the built Microsoft.Extensions.Hosting.IHost instance for Atom-specific behaviors.
public static IHost UseAtom(this IHost host)
Parameters
hostIHostThe Microsoft.Extensions.Hosting.IHost instance to configure.
Returns
- IHost
The configured Microsoft.Extensions.Hosting.IHost instance.
Remarks
This method invokes ConfigureHost(IHost) of the build definition type passed to AddAtom<TBuilder, TBuild>(TBuilder, string[]), allowing for post-build host configuration. It does nothing when the host was not configured with AddAtom<TBuilder, TBuild>(TBuilder, string[]). The build definition itself is not resolved.