Ejemplo n.º 1
0
 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));
     }
 }
Ejemplo n.º 2
0
        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);
            }
Ejemplo n.º 3
0
        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));
            }
        }