Esempio n. 1
0
 public static INamedServiceProvider BuildServiceProvider(this IServiceDefintions services)
 {
     if (services == null)
     {
         throw new ArgumentNullException(nameof(services));
     }
     services.AddInternalServiceDefintions();
     return(new ServiceProvider(services));
 }
 public DelegateServiceDefintionHandler(IServiceDefintions services)
 {
     handlers = services.Select(i =>
     {
         if (i is DelegateServiceDefintion defintion &&
             defintion.ServiceType == typeof(IDelegateServiceDefintionHandler))
         {
             return((IDelegateServiceDefintionHandler)defintion.ImplementationFactory(null));
         }
Esempio n. 3
0
 public static IServiceDefintions AddInstance(this IServiceDefintions services, Lifetime lifetime, Type serviceType, Type implementationType, object implementationInstance, string name = null)
 {
     if (implementationInstance == null)
     {
         throw new ArgumentNullException(nameof(implementationInstance));
     }
     if (!serviceType.IsInstanceOfType(implementationInstance))
     {
         throw new ArgumentException($"{implementationInstance} is not instance of type {serviceType}");
     }
     services.Add(ServiceDefintions.Define(serviceType, implementationType, lifetime, i => implementationInstance, name));
     return(services);
 }
Esempio n. 4
0
        internal static void AddInternalServiceDefintions(this IServiceDefintions services)
        {
            if (!services.Contains <IServiceProvider>())
            {
                services.AddScoped(i => i);
            }

            if (!services.Contains <IServiceScopeFactory>())
            {
                services.AddScoped <IServiceScopeFactory>(i => new ServiceScopeFactory(i));
            }

            if (!services.Contains <IDelegateServiceDefintionHandler, PropertyInjector>())
            {
                services.AddScoped <IDelegateServiceDefintionHandler, PropertyInjector>(i => new PropertyInjector());
            }
        }
Esempio n. 5
0
 public static IServiceDefintions AddSingleton(this IServiceDefintions services, Type serviceType, object instance, string name = null)
 {
     return(services.AddInstance(Lifetime.Singleton, serviceType, serviceType, instance, name));
 }
Esempio n. 6
0
 public static IServiceDefintions AddSingleton(this IServiceDefintions services, Type serviceType, string name = null)
 {
     return(services.AddSingleton(serviceType, serviceType, null, name));
 }
Esempio n. 7
0
 public static IServiceDefintions AddSingleton(this IServiceDefintions services, Type serviceType, Type implementationType, Func <INamedServiceProvider, object> serviceFactory = null, string name = null)
 {
     return(services.Add(Lifetime.Singleton, serviceType, implementationType, serviceFactory, name));
 }
Esempio n. 8
0
 public static bool Contains <TService, TImplementation>(this IServiceDefintions services)
     where TService : class where TImplementation : TService
 {
     return(services.Contains(typeof(TService), typeof(TImplementation)));
 }
Esempio n. 9
0
 public static bool Contains(this IServiceDefintions services, Type serviceType, Type implementationType)
 {
     return(services.Any(x => x.ServiceType == serviceType && x.ImplementationType == implementationType));
 }
Esempio n. 10
0
 public static IServiceDefintions AddSingleton <TService, TImplementation>(this IServiceDefintions services,
                                                                           TImplementation implementation, string name = null) where TService : class where TImplementation : TService
 {
     return(services.AddInstance(Lifetime.Singleton, typeof(TService), typeof(TImplementation), implementation, name));
 }
Esempio n. 11
0
 public static IServiceDefintions AddScoped <TService, TImplementation>(this IServiceDefintions services, string name = null)
     where TService : class where TImplementation : TService
 {
     return(services.AddScoped(typeof(TService), typeof(TImplementation), null, name));
 }
Esempio n. 12
0
 public static IServiceDefintions AddSingleton <TService>(this IServiceDefintions services, Func <INamedServiceProvider, TService> serviceFactory, string name = null) where TService : class
 {
     return(services.AddSingleton(typeof(TService), typeof(TService), serviceFactory, name));
 }
Esempio n. 13
0
 public static IServiceDefintions Add(this IServiceDefintions services, Lifetime lifetime, Type serviceType, Type implementationType, Func <INamedServiceProvider, object> serviceFactory = null, string name = null)
 {
     services.Add(ServiceDefintions.Define(serviceType, implementationType, lifetime, serviceFactory, name));
     return(services);
 }
Esempio n. 14
0
 public static IServiceDefintions AddTransient <TService>(this IServiceDefintions services, Func <INamedServiceProvider, TService> implementationFactory, string name = null)
     where TService : class
 {
     return(services.AddTransient(typeof(TService), typeof(TService), implementationFactory, name));
 }
Esempio n. 15
0
 public static IServiceDefintions AddTransient <TService>(this IServiceDefintions services, string name = null)
     where TService : class
 {
     return(services.AddTransient(typeof(TService), typeof(TService), null, name));
 }
Esempio n. 16
0
 public static IServiceDefintions AddScoped <TService, TImplementation>(this IServiceDefintions services,
                                                                        Func <INamedServiceProvider, TImplementation> implementationFactory, string name = null) where TService : class where TImplementation : TService
 {
     return(services.AddScoped(typeof(TService), typeof(TImplementation), i => implementationFactory(i), name));
 }
Esempio n. 17
0
 public static IServiceDefintions AddSingleton(this IServiceDefintions services, Type serviceType, Func <INamedServiceProvider, object> serviceFactory, string name = null)
 {
     return(services.AddSingleton(serviceType, serviceType, serviceFactory, name));
 }
Esempio n. 18
0
 public static bool Contains <TService>(this IServiceDefintions services) where TService : class
 {
     return(services.Contains(typeof(TService)));
 }
Esempio n. 19
0
 public ServiceProvider(IServiceDefintions services)
 {
     engine = new ServiceProviderEngine(services, new DelegateServiceDefintionHandler(services));
 }
Esempio n. 20
0
 public static IServiceDefintions AddSingleton <TService>(this IServiceDefintions services, TService service, string name = null) where TService : class
 {
     return(services.AddSingleton(typeof(TService), service, name));
 }