Example #1
0
        public static Expression GenExpression(this InjectionMember injectionMember, Type registrationType, int lifetimeManagerIndex, IQuickInjectContainer container)
        {
            var injectionMemberType = injectionMember.GetType();
            var baseType            = injectionMemberType.GetTypeInfo().BaseType;

            if (baseType == typeof(InjectionMember))
            {
                return(new ParameterizedLambdaExpressionInjectionFactoryMethodCallExpression(injectionMember, lifetimeManagerIndex));
            }

            throw new Exception("Unknown registration factory");
        }
 public static IQuickInjectContainer RegisterType <T>(this IQuickInjectContainer container, InjectionMember injectionMember = null)
 {
     return(container.RegisterType(null, typeof(T), null, injectionMember));
 }
 public static IQuickInjectContainer RegisterType(this IQuickInjectContainer container, Type t, LifetimeManager lifetimeManager, InjectionMember injectionMember = null)
 {
     return(container.RegisterType(null, t, lifetimeManager, injectionMember));
 }
 public static IQuickInjectContainer RegisterType(this IQuickInjectContainer container, Type from, Type to, InjectionMember injectionMember = null)
 {
     return(container.RegisterType(from, to, null, injectionMember));
 }
 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));
 }
 public ParameterizedLambdaExpressionInjectionFactoryMethodCallExpression(InjectionMember injectionMember, int lifetimeManagerIndex)
 {
     this.injectionMember      = injectionMember;
     this.lifetimeManagerIndex = lifetimeManagerIndex;
 }
Example #7
0
        public IQuickInjectContainer RegisterType(Type from, Type to, LifetimeManager lifetimeManager, InjectionMember injectionMember = null)
        {
            this.EnsureIsNotSealed();

            if (to == null)
            {
                throw new ArgumentNullException(nameof(to));
            }

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

            var handler = this.Registering;

            handler?.Invoke(this, new RegisterEventArgs(from, to, lifetimeManager));

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

                int lifetimeManagerIndex = -1;

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

                    lock (StaticLock)
                    {
                        lifetimeManagers.Add(lifetimeManager);
                        lifetimeManagerIndex = lifetimeManagers.Count - 1;
                    }

                    this.lifetimeIndexTable.Add(lifetimeManager, lifetimeManagerIndex);
                }

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

            return(this);
        }