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>)); }
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); }
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); }
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>)); }