예제 #1
0
        public void CanChainGenericTypesViaRegisterTypeMethod()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>),
                                                      new InjectionConstructor(new ResolvedParameter(typeof(ICommand <>), "concrete")))
                                        .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "concrete");

            ICommand <User>       cmd    = container.Resolve <ICommand <User> >();
            LoggingCommand <User> logCmd = (LoggingCommand <User>)cmd;

            Assert.NotNull(logCmd.Inner);
            AssertExtensions.IsInstanceOfType(logCmd.Inner, typeof(ConcreteCommand <User>));
        }
예제 #2
0
        public void CanConfigureInjectionForNonGenericMethodOnGenericClass()
        {
            IUnityContainer container = new UnityContainer();

            container.RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>),
                                   new InjectionConstructor(),
                                   new InjectionMethod("InjectMe"));

            ICommand <Account>       result    = container.Resolve <ICommand <Account> >();
            LoggingCommand <Account> logResult = (LoggingCommand <Account>)result;

            Assert.True(logResult.WasInjected);
        }
예제 #3
0
        public void ConfiguredGenericMethodInjectionIsCalled()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>),
                                                      new InjectionConstructor(new ResolvedParameter(typeof(ICommand <>), "concrete")),
                                                      new InjectionMethod("ChainedExecute", new ResolvedParameter(typeof(ICommand <>), "inner")))
                                        .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "concrete")
                                        .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "inner");

            ICommand <Account>       result = container.Resolve <ICommand <Account> >();
            LoggingCommand <Account> lc     = (LoggingCommand <Account>)result;

            Assert.True(lc.ChainedExecuteWasCalled);
        }
예제 #4
0
        public void GenericPropertyIsActuallyInjected()
        {
            IUnityContainer container = new UnityContainer()
                                        .RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>),
                                                      new InjectionConstructor(),
                                                      new InjectionProperty("Inner",
                                                                            new ResolvedParameter(typeof(ICommand <>), "inner")))
                                        .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "inner");

            ICommand <Account> result = container.Resolve <ICommand <Account> >();

            LoggingCommand <Account> actualResult = (LoggingCommand <Account>)result;

            Assert.NotNull(actualResult.Inner);
            AssertExtensions.IsInstanceOfType(actualResult.Inner, typeof(ConcreteCommand <Account>));
        }