Ejemplo n.º 1
0
        public static Expression GenExpression(this InjectionMember injectionMember, Type registrationType, IQuickInjectContainer container)
        {
            var injectionMemberType = injectionMember.GetType();
            var baseType            = injectionMemberType.GetTypeInfo().BaseType;

            if (baseType == typeof(InjectionMember))
            {
                return(new ParameterizedLambdaExpressionInjectionFactoryMethodCallExpression(injectionMember.Factory));
            }

            throw new Exception("Unknown registration factory");
        }
Ejemplo n.º 2
0
        public IQuickInjectContainer RegisterType(Type from, Type to, LifetimeManager lifetimeManager, InjectionMember injectionMember = null)
        {
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            if ((from != null && from.GetTypeInfo().IsGenericTypeDefinition) || to.GetTypeInfo().IsGenericTypeDefinition)
            {
                throw new ArgumentException("Open Generic Types are not supported");
            }

            this.Registering(this, new RegisterEventArgs(from, to, lifetimeManager));

            lock (this.lockObj)
            {
                if (from != null)
                {
                    this.typeMappingTable.AddOrUpdate(from, to);
                }

                if (lifetimeManager != null)
                {
                    this.lifetimeTable.AddOrUpdate(to, lifetimeManager);
                }

                if (injectionMember != null)
                {
                    this.factoryExpressionTable.AddOrUpdate(to, injectionMember.GenExpression(to, this));
                }

                this.ClearBuildPlans();
            }

            return(this);
        }
Ejemplo n.º 3
0
 public static IQuickInjectContainer RegisterType <T>(this IQuickInjectContainer container, InjectionMember injectionMember = null)
 {
     return(container.RegisterType(null, typeof(T), null, injectionMember));
 }
Ejemplo n.º 4
0
 public static IQuickInjectContainer RegisterType(this IQuickInjectContainer container, Type t, LifetimeManager lifetimeManager, InjectionMember injectionMember = null)
 {
     return(container.RegisterType(null, t, lifetimeManager, injectionMember));
 }
Ejemplo n.º 5
0
 public static IQuickInjectContainer RegisterType(this IQuickInjectContainer container, Type from, Type to, InjectionMember injectionMember = null)
 {
     return(container.RegisterType(from, to, null, injectionMember));
 }
Ejemplo n.º 6
0
 public static IQuickInjectContainer RegisterType <TFrom, TTo>(this IQuickInjectContainer container, LifetimeManager lifetimeManager, InjectionMember injectionMember = null) where TTo : TFrom
 {
     return(container.RegisterType(typeof(TFrom), typeof(TTo), lifetimeManager, injectionMember));
 }