Skip to content

Instantly share code, notes, and snippets.

@MichalGrzegorzak
Created September 30, 2023 09:09
Show Gist options
  • Save MichalGrzegorzak/da1f4f560fc7a2b96288839d0cbbe952 to your computer and use it in GitHub Desktop.
Save MichalGrzegorzak/da1f4f560fc7a2b96288839d0cbbe952 to your computer and use it in GitHub Desktop.
AddConfigOptionsFromConfigSection
internal static IServiceCollection AddConfigOptionsFromConfigSection<T>(this IServiceCollection services, string configSectionName) where T : class
{
services.AddOptions<T>().Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection(configSectionName).Bind(settings);
});
return services;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment