Пример #1
0
 public static void SetOptions <T>(this IServiceCollection serviceCollection, IConfigurationPackage package, string sectionCode) where T : class => serviceCollection.Configure <T>(c => SetOptions <T>(package, sectionCode));
Пример #2
0
        public static void AddSingletonProvider <T, TU>(this IServiceCollection serviceCollection, IConfigurationPackage package, string sectionCode) where T : class where TU : class
        {
            var targetType = typeof(T);

            var targetProvider = package?.Provider?.ContainsKey(targetType) == true ? (Type)package.Provider[targetType] : IoC.GetClassesByInterface <T>().FirstOrDefault();

            if (targetProvider != null)
            {
                serviceCollection.AddSingleton(typeof(T), targetProvider);
                Status.Providers.Add(targetType);
            }

            serviceCollection.SetOptions <TU>(package, sectionCode);
        }
Пример #3
0
 public static T SetOptions <T>(IConfigurationPackage package, string sectionCode) where T : class =>
 package?.Provider[typeof(T)] != null
         ? (T)package.Provider[typeof(T)]
 : IoC.GetClassesByInterface <T>().FirstOrDefault()?.CreateInstance <T>() ??
 Options.GetSection(sectionCode).Get <T>();