mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-12 11:32:10 +08:00
31 lines
1010 B
C#
31 lines
1010 B
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace BuildingBlocks.Utils;
|
|
|
|
public static class ConfigurationExtensions
|
|
{
|
|
public static TModel GetOptions<TModel>(this IConfiguration configuration, string section) where TModel : new()
|
|
{
|
|
var model = new TModel();
|
|
configuration.GetSection(section).Bind(model);
|
|
return model;
|
|
}
|
|
|
|
public static TModel GetOptions<TModel>(this IServiceCollection service, string section) where TModel : new()
|
|
{
|
|
var model = new TModel();
|
|
var configuration = service.BuildServiceProvider().GetService<IConfiguration>();
|
|
configuration?.GetSection(section).Bind(model);
|
|
return model;
|
|
}
|
|
|
|
public static TModel GetOptions<TModel>(this WebApplication app, string section) where TModel : new()
|
|
{
|
|
var model = new TModel();
|
|
app.Configuration?.GetSection(section).Bind(model);
|
|
return model;
|
|
}
|
|
}
|