public static class ConfigurationExtensions { public static TConfig MapConfigSection<TConfig>(this IServiceCollection services, IConfiguration config, string name) where TConfig: class { var settings = config.GetSection(name).Get<TConfig>(); services.AddSingleton(settings); return settings; } }
services.MapConfigSection<PowerBISettings>(config, "PowerBI");
public class MySampleClass { private PowerBISettings _powerBiSettings; public MySampleClass( [FromServices] PowerBISettings powerBiSettings ) { _powerBiSettings = powerBiSettings; } }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.