Background and motivation
The Microsoft.Extensions.AmbientMetadata has a UseApplicationMetadata that currently targets the old IHostBuilder interface:
|
public static IHostBuilder UseApplicationMetadata(this IHostBuilder builder, string sectionName = DefaultSectionName) |
I would like to propose the creation of a version of this method that targets IHostApplicationBuilder instead, which is the more modern, property-based hosting API.
API Proposal
public static class ApplicationMetadataHostBuilderExtensions
{
public static TBuilder UseApplicationMetadata<TBuilder>(this TBuilder builder, string sectionName = DefaultSectionName)
where TBuilder : IHostApplicationBuilder;
}
API Usage
var builder = WebApplication.CreateBuilder(args);
builder.UseApplicationMetadata();
// ...
var app = builder.Build();
// ,,,
await app.RunAsync();
Alternative Designs
Methods that work directly on the top-level IHostApplicationBuilder are somewhat unusual, so perhaps the library should also (or instead) consider providing an easier-to-use versions of:
|
public static IServiceCollection AddApplicationMetadata(this IServiceCollection services, IConfigurationSection section) |
So that we can simply use:
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddApplicationMetadata();
builder.Services.AddApplicationMetadata();
Instead.
Currently, the second call is not possible as the caller is asked to provide the configuration section.
Risks
I believe zero, considering these would be additive APIs to the ones that exist today, so people can opt-in to the new HostApplicationBuilder-based configuration interface.
Background and motivation
The
Microsoft.Extensions.AmbientMetadatahas aUseApplicationMetadatathat currently targets the oldIHostBuilderinterface:extensions/src/Libraries/Microsoft.Extensions.AmbientMetadata.Application/ApplicationMetadataHostBuilderExtensions.cs
Line 26 in 6eb7ad8
I would like to propose the creation of a version of this method that targets
IHostApplicationBuilderinstead, which is the more modern, property-based hosting API.API Proposal
API Usage
Alternative Designs
Methods that work directly on the top-level
IHostApplicationBuilderare somewhat unusual, so perhaps the library should also (or instead) consider providing an easier-to-use versions of:extensions/src/Libraries/Microsoft.Extensions.AmbientMetadata.Application/ApplicationMetadataServiceCollectionExtensions.cs
Line 23 in 6eb7ad8
So that we can simply use:
Instead.
Currently, the second call is not possible as the caller is asked to provide the configuration section.
Risks
I believe zero, considering these would be additive APIs to the ones that exist today, so people can opt-in to the new
HostApplicationBuilder-based configuration interface.