-
Notifications
You must be signed in to change notification settings - Fork 847
Description
Background and motivation
The Microsoft.Extensions.AmbientMetadata has a UseApplicationMetadata that currently targets the old IHostBuilder interface:
Line 26 in 6eb7ad8
| 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:
Line 23 in 6eb7ad8
| 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.