private static void AddProxy <T>(OptionsAttribute attribute, IServiceCollection services) where T : class { foreach (var contract in typeof(T).GetInterfaces().Concat(new Type[] { typeof(T) })) { services.AddTransient(contract, provider => ActivatorUtilities.CreateInstance <T>(provider)); } }
private static void AddOptions <T>(OptionsAttribute attribute, IServiceCollection services) where T : class, new() { services .AddOptions <T>() .Configure <IConfiguration>((options, config) => config.GetSection(attribute.SectionName)?.Bind(options)); foreach (var contract in typeof(T).GetInterfaces().Concat(new Type[] { typeof(T) })) { services.AddTransient(contract, ResolveOptions); }
private static void AddProxy <T>(OptionsAttribute attribute, IServiceCollection services) where T : class { if (attribute is null) { throw new ArgumentNullException(nameof(attribute)); } if (services is null) { throw new ArgumentNullException(nameof(services)); } foreach (var contract in typeof(T).GetInterfaces().Concat(new Type[] { typeof(T) })) { services.AddTransient(contract, provider => ActivatorUtilities.CreateInstance <T>(provider)); } }