private Expression GenerateResolveExpression(IQuickInjectContainer quickInjectContainer, ParameterExpression variable, TypeRegistration registration)
        {
            Type       argumentType      = registration.RegistrationType;
            MethodInfo resolve           = QuickInjectContainerType.GetRuntimeMethods().Single(x => x.Name == "Resolve" && x.GetParameters().Length == 1);
            var        containerResolveT = Expression.Call(Expression.Constant(quickInjectContainer, QuickInjectContainerType), resolve, Expression.Constant(argumentType));

            return(Expression.Assign(variable, Expression.Convert(containerResolveT, argumentType)));
        }
Beispiel #2
0
        internal void InitializeExtension(ExtensionContext extensionContext)
        {
            if (extensionContext == null)
            {
                throw new ArgumentNullException(nameof(extensionContext));
            }

            this.container = extensionContext.Container;
            this.context   = extensionContext;
            this.Initialize();
        }
        public ExpressionGenerator(IQuickInjectContainer container, List <TypeRegistration> registrations)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (registrations == null)
            {
                throw new ArgumentNullException("registrations");
            }

            this.container     = container;
            this.registrations = registrations;
            this.ResolutionContextParameter = Expression.Parameter(typeof(object), "resolutionContextParameter");
            this.SetupLocalVariableExpressions();
        }
Beispiel #4
0
        public void ChildRegistrationIsChosenWhenResolvedFromChild()
        {
            IA aParent = new A();
            IA aChild  = new A();

            var parent = new QuickInjectContainer();

            parent.RegisterInstance(aParent);

            IQuickInjectContainer child = parent.CreateChildContainer();

            child.RegisterInstance(aChild);


            Assert.IsTrue(aChild == child.Resolve <IA>());
            Assert.IsTrue(aParent == parent.Resolve <IA>());
        }
Beispiel #5
0
        public void RegisterWithParentAndChild()
        {
            //create unity container
            var parentuc = new QuickInjectContainer();

            //register type UnityTestClass
            parentuc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager());

            UnityTestClass mytestparent = parentuc.Resolve <UnityTestClass>();

            mytestparent.Name = "Hello World";
            IQuickInjectContainer childuc = parentuc.CreateChildContainer();

            childuc.RegisterType <UnityTestClass>(new ContainerControlledLifetimeManager());

            UnityTestClass mytestchild = childuc.Resolve <UnityTestClass>();

            Assert.AreNotSame(mytestparent.Name, mytestchild.Name);
        }
Beispiel #6
0
        public void DuplicateRegInParentAndChild()
        {
            IA a = new A();
            IB b = new B(a);

            var parent = new QuickInjectContainer();

            parent.RegisterInstance(a).RegisterInstance(b);

            IQuickInjectContainer child = parent.CreateChildContainer();

            var childA  = child.Resolve <IA>();
            var parentA = parent.Resolve <IA>();

            var childB  = child.Resolve <IB>();
            var parentB = parent.Resolve <IB>();

            Assert.IsTrue(childA == parentA);
            Assert.IsTrue(childB == parentB);
        }
 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));
 }
Beispiel #9
0
 public static IQuickInjectContainer RegisterType <TFrom, TTo>(this IQuickInjectContainer container)
 {
     return(container.RegisterType(typeof(TFrom), typeof(TTo), null));
 }
 public static T Resolve <T>(this IQuickInjectContainer container, object resolutionContext)
 {
     return((T)container.Resolve(typeof(T), resolutionContext));
 }
 public static IQuickInjectContainer RegisterInstance(this IQuickInjectContainer container, Type t, object instance)
 {
     return(container.RegisterInstance(t, instance, new ContainerControlledLifetimeManager()));
 }
Beispiel #12
0
 public ContainerReturnsDifferentInstancesOnDifferentThreads_ThreadInformation(IQuickInjectContainer container)
 {
     _container     = container;
     _threadResults = new Dictionary <Thread, IHaveManyGenericTypesClosed>();
 }
Beispiel #13
0
 public static IQuickInjectContainer RegisterType <T>(this IQuickInjectContainer container, LifetimeManager lifetime)
 {
     return(container.RegisterType(null, typeof(T), lifetime));
 }
Beispiel #14
0
 public static IQuickInjectContainer RegisterType <TFrom, TTo>(this IQuickInjectContainer container, LifetimeManager lifetime)
 {
     return(container.RegisterType(typeof(TFrom), typeof(TTo), lifetime));
 }
 public static IQuickInjectContainer RegisterType(this IQuickInjectContainer container, Type t, LifetimeManager lifetimeManager, InjectionMember injectionMember = null)
 {
     return(container.RegisterType(null, t, lifetimeManager, injectionMember));
 }
 public static IQuickInjectContainer RegisterInstance <TInterface>(this IQuickInjectContainer container, TInterface instance, LifetimeManager lifetimeManager)
     where TInterface : class
 {
     return(container.RegisterInstance(typeof(TInterface), instance, lifetimeManager));
 }
Beispiel #17
0
 public static IQuickInjectContainer RegisterInstance <TInterface>(this IQuickInjectContainer container, TInterface instance)
 {
     return(container.RegisterInstance(typeof(TInterface), instance, new ContainerControlledLifetimeManager()));
 }
 public static T Resolve <T>(this IQuickInjectContainer container)
 {
     return((T)container.Resolve(typeof(T)));
 }
Beispiel #19
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");
        }
 public static IQuickInjectContainer RegisterType <T>(this IQuickInjectContainer container, InjectionMember injectionMember = null)
 {
     return(container.RegisterType(null, typeof(T), null, injectionMember));
 }
Beispiel #21
0
 public static IQuickInjectContainer RegisterType <T>(this IQuickInjectContainer container)
 {
     return(container.RegisterType(null, typeof(T), new TransientLifetimeManager()));
 }