Exemple #1
0
 public ServiceInjectionConfigurarion(Type serviceType,
                                      Type implementationType, InjectionLifetime lifetime)
 {
     ServiceType        = serviceType;
     ImplementationType = implementationType;
     Lifetime           = lifetime;
 }
        public static void Add(this IServiceCollection serviceCollection, InjectionLifetime ioCLifetime, params Type[] types)
        {
            if (types == null)
            {
                throw new ArgumentNullException(types + nameof(types));
            }

            foreach (var type in types)
            {
                serviceCollection.Add(type, ioCLifetime);
            }
        }
        public static void Add(this IServiceCollection serviceCollection, Type type, InjectionLifetime ioCLifetime)
        {
            switch (ioCLifetime)
            {
            case InjectionLifetime.Singleton:
                serviceCollection.AddSingleton(type);
                break;

            case InjectionLifetime.Transient:
                serviceCollection.AddTransient(type);
                break;

            case InjectionLifetime.Scoped:
                serviceCollection.AddScoped(type);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(ioCLifetime), ioCLifetime, null);
            }
        }
 public static void Add <T>(this IServiceCollection serviceCollection, InjectionLifetime ioCLifetime)
 {
     serviceCollection.Add(typeof(T), ioCLifetime);
 }