/// <summary>
 /// To Microsoft Lifetime
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static ServiceLifetime ToMsLifetime(this DependencyLifetimeType type)
 {
     return(type switch
     {
         DependencyLifetimeType.Scoped => ServiceLifetime.Scoped,
         DependencyLifetimeType.Singleton => ServiceLifetime.Singleton,
         DependencyLifetimeType.Transient => ServiceLifetime.Transient,
         _ => ServiceLifetime.Transient
     });
 /// <summary>
 /// To NCC AspectCore lifetime
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static Lifetime ToAspectCoreLifetime(this DependencyLifetimeType type)
 {
     return(type switch
     {
         DependencyLifetimeType.Scoped => Lifetime.Scoped,
         DependencyLifetimeType.Singleton => Lifetime.Singleton,
         DependencyLifetimeType.Transient => Lifetime.Transient,
         _ => Lifetime.Transient
     });
 /// <summary>
 /// Create
 /// </summary>
 /// <param name="instanceFunc"></param>
 /// <param name="implementationType"></param>
 /// <param name="lifetimeType"></param>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForResolvedObjectDelegate(Func <IDefinedResolver, object> instanceFunc, Type implementationType,
                                                                         DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = implementationType,
         ResolveFuncForImplementation = instanceFunc,
         ProxyType = DependencyProxyType.ResolvedInstanceSelfFunc,
         LifetimeType = lifetimeType
     });
 }
        /// <summary>
        /// Is registered
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lifetimeType"></param>
        /// <returns></returns>
        public virtual bool IsRegistered <T>(DependencyLifetimeType lifetimeType)
        {
            var type = typeof(T);

            return(_descriptors.Any(x => x.RegisterType == type && x.LifetimeType == lifetimeType));
        }
 /// <summary>
 /// Is registered
 /// </summary>
 /// <param name="type"></param>
 /// <param name="lifetimeType"></param>
 /// <returns></returns>
 public virtual bool IsRegistered(Type type, DependencyLifetimeType lifetimeType)
 {
     return(type != null &&
            _descriptors.Any(x => x.RegisterType == type && x.LifetimeType == lifetimeType));
 }
 /// <summary>
 /// Create
 /// </summary>
 /// <typeparam name="TService"></typeparam>
 /// <typeparam name="TImplementation"></typeparam>
 /// <param name="instance"></param>
 /// <param name="lifetimeType"></param>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForService <TService, TImplementation>(TImplementation instance, DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = typeof(TService),
         ServiceType = typeof(TService),
         InstanceOfImplementation = instance,
         ProxyType = DependencyProxyType.TypeToInstance,
         LifetimeType = lifetimeType
     });
 }
 /// <summary>
 /// Create
 /// </summary>
 /// <param name="instanceFunc"></param>
 /// <param name="implementationType"></param>
 /// <param name="lifetimeType"></param>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForInstanceDelegate(Func <object> instanceFunc, Type implementationType, DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = implementationType,
         InstanceFuncForImplementation = instanceFunc,
         ProxyType = DependencyProxyType.InstanceSelfFunc,
         LifetimeType = lifetimeType
     });
 }
 /// <summary>
 /// Create
 /// </summary>
 /// <param name="instanceFunc"></param>
 /// <param name="lifetimeType"></param>
 /// <typeparam name="TImplementation"></typeparam>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForResolvedInstanceDelegate <TImplementation>(Func <IDefinedResolver, TImplementation> instanceFunc,
                                                                                             DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = typeof(TImplementation),
         ImplementationTypeSelf = typeof(TImplementation),
         ResolveFuncForImplementation = resolver => instanceFunc(resolver),
         ProxyType = DependencyProxyType.ResolvedInstanceSelfFunc,
         LifetimeType = lifetimeType
     });
 }
 /// <summary>
 /// Create
 /// </summary>
 /// <typeparam name="TImplementation"></typeparam>
 /// <param name="instanceFunc"></param>
 /// <param name="lifetimeType"></param>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForInstanceDelegate <TImplementation>(Func <TImplementation> instanceFunc, DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = typeof(TImplementation),
         ImplementationTypeSelf = typeof(TImplementation),
         InstanceFuncForImplementation = () => instanceFunc(),
         ProxyType = DependencyProxyType.InstanceSelfFunc,
         LifetimeType = lifetimeType
     });
 }
 /// <summary>
 /// Create
 /// </summary>
 /// <param name="instanceFunc"></param>
 /// <param name="lifetimeType"></param>
 /// <typeparam name="TService"></typeparam>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForResolvedServiceDelegate <TService>(Func <IDefinedResolver, object> instanceFunc, DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = typeof(TService),
         ServiceType = typeof(TService),
         ResolveFuncForImplementation = instanceFunc,
         ProxyType = DependencyProxyType.TypeToResolvedInstanceFunc,
         LifetimeType = lifetimeType
     });
 }
 /// <summary>
 /// Create
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="implementationType"></param>
 /// <param name="lifetimeType"></param>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForObject(object instance, Type implementationType, DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = implementationType,
         InstanceOfImplementation = instance,
         ProxyType = DependencyProxyType.InstanceSelf,
         LifetimeType = lifetimeType
     });
 }
 /// <summary>
 /// Create
 /// </summary>
 /// <param name="serviceType"></param>
 /// <param name="implementationType"></param>
 /// <param name="lifetimeType"></param>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForType(Type serviceType, Type implementationType, DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = serviceType,
         ServiceType = serviceType,
         ImplementationType = implementationType,
         ProxyType = DependencyProxyType.TypeToType,
         LifetimeType = lifetimeType
     });
 }
 /// <summary>
 /// Create
 /// </summary>
 /// <typeparam name="TImplementationSelf"></typeparam>
 /// <param name="lifetimeType"></param>
 /// <returns></returns>
 public static DependencyProxyDescriptor CreateForInstanceSelf <TImplementationSelf>(DependencyLifetimeType lifetimeType)
 {
     return(new DependencyProxyDescriptor
     {
         RegisterType = typeof(TImplementationSelf),
         ImplementationTypeSelf = typeof(TImplementationSelf),
         ProxyType = DependencyProxyType.TypeSelf,
         LifetimeType = lifetimeType
     });
 }
示例#14
0
 /// <summary>
 /// Create a new instance of <see cref="ComponentsRegistration"/>.
 /// </summary>
 /// <param name="serviceType"></param>
 /// <param name="many"></param>
 /// <param name="lifetime"></param>
 public ComponentsRegistration(Type serviceType, Many many, DependencyLifetimeType lifetime)
 {
     ServiceType = serviceType;
     Many        = many;
     Lifetime    = lifetime;
 }