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.IsNotNull(logCmd.Inner); AssertExtensions.IsInstanceOfType(logCmd.Inner, typeof(ConcreteCommand <User>)); }
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.IsTrue(logResult.WasInjected); }
public void CanInjectNestedGenerics() { IUnityContainer container = new UnityContainer() .RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>), new InjectionConstructor(new ResolvedParameter(typeof(ICommand <>), "concrete"))) .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "concrete"); ICommand <Nullable <Customer> > cmd = container.Resolve <ICommand <Nullable <Customer> > >(); LoggingCommand <Nullable <Customer> > logCmd = (LoggingCommand <Nullable <Customer> >)cmd; Assert.IsNotNull(logCmd.Inner); Assert.IsInstanceOfType(logCmd.Inner, typeof(ConcreteCommand <Nullable <Customer> >)); }
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.IsTrue(lc.ChainedExecuteWasCalled); }
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.IsNotNull(actualResult.Inner); Assert.IsInstanceOfType(actualResult.inner, typeof(ConcreteCommand <Account>)); }