using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace BuildingBlocks.Utils; public static class ConfigurationExtensions { public static TModel GetOptions(this IConfiguration configuration, string section) where TModel : new() { var model = new TModel(); configuration.GetSection(section).Bind(model); return model; } public static TModel GetOptions(this IServiceCollection service, string section) where TModel : new() { var model = new TModel(); var configuration = service.BuildServiceProvider().GetService(); configuration?.GetSection(section).Bind(model); return model; } public static TModel GetOptions(this WebApplication app, string section) where TModel : new() { var model = new TModel(); app.Configuration?.GetSection(section).Bind(model); return model; } }