Description
Background and motivation
The Microsoft.Extensions.AmbientMetadata
has a UseApplicationMetadata
that currently targets the old IHostBuilder
interface:
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 ApplicationMetadataHostApplicationBuilderExtensions
{
public static IHostApplicationBuilder UseApplicationMetadata(this IHostApplicationBuilder builder);
}
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:
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.