| | 1 | | using System; |
| | 2 | | using Microsoft.Extensions.Configuration; |
| | 3 | |
|
| | 4 | | namespace ApplicationCore |
| | 5 | | { |
| | 6 | | public interface IConfigProvider |
| | 7 | | { |
| | 8 | | T GetConfig<T>(IConfigurationRoot config) where T : new(); |
| | 9 | | } |
| | 10 | |
|
| | 11 | | public class ConfigProvider : IConfigProvider |
| | 12 | | { |
| | 13 | | public T GetConfig<T>(IConfigurationRoot configRoot) where T : new() |
| 12 | 14 | | { |
| 12 | 15 | | if (configRoot is null) |
| 1 | 16 | | { |
| 1 | 17 | | throw new ArgumentNullException(nameof(configRoot)); |
| | 18 | | } |
| | 19 | |
|
| 11 | 20 | | var config = new T(); |
| 22 | 21 | | configRoot.GetSection(typeof(T).Name).Bind(config, x => x.BindNonPublicProperties = true); |
| | 22 | |
|
| 11 | 23 | | return config; |
| 11 | 24 | | } |
| | 25 | | } |
| | 26 | | } |