Class ConfigureHostBuilderAttribute
Marks an interface as a source of host builder configuration for any build definition that implements it.
[AttributeUsage(AttributeTargets.Interface)]
public sealed class ConfigureHostBuilderAttribute : Attribute
- Inheritance
-
objectAttributeConfigureHostBuilderAttribute
Examples
[ConfigureHostBuilder]
public partial interface IMyModule
{
protected static partial void ConfigureHostBuilderFromIMyModule(IHostApplicationBuilder builder) =>
builder.Services.AddSingleton<IMyService, MyService>();
}
[BuildDefinition]
internal partial class Build : BuildDefinition, IMyModule;
Remarks
The interface must be partial. The source generator declares
protected static partial void ConfigureHostBuilderFrom{InterfaceName}(IHostApplicationBuilder builder) on
the interface, which the interface must implement (analyzer AT0003 reports a missing implementation). The
generated ConfigureHostBuilder(IHostApplicationBuilder) of every build definition that implements the
interface calls this method before the host is built, without constructing the build definition.
Constructors
ConfigureHostBuilderAttribute()
public ConfigureHostBuilderAttribute()