public void ShouldThrowExceptionWhenPublicConstructorNotFoundInHierarchy() { IContainer container = new InfuseContainer(); container.Register <NoPublicConstructor, NoPublicConstructor>(); container.Register <DependsOnNonPublicConstructorClass, DependsOnNonPublicConstructorClass>(); Assert.Throws <InvalidOperationException>(() => { var oops = container.Resolve <DependsOnNonPublicConstructorClass>(); }); }
public static IContainer ConfigureInfuseContainer() { IContainer infuseContainer = new InfuseContainer(); infuseContainer.RegisterSingleton <IHomeRepository, HomeRepository>(); infuseContainer.Register <HomeController, HomeController>(); infuseContainer.Register <AccountController, AccountController>(); infuseContainer.Register <ManageController, ManageController>(); infuseContainer.Register <MoviesController, MoviesController>(); infuseContainer.Register <HelloWorldController, HelloWorldController>(); return(infuseContainer); }
public void SingletonIsSharedBetweenHierarchy() { var container = new InfuseContainer(); container.Register <Logger, Logger>(LifecycleType.Singleton); container.Register <TestLoggerController, TestLoggerController>(LifecycleType.Singleton); container.Register <TestLoggerRepository, TestLoggerRepository>(LifecycleType.Singleton); string str = "Hello"; var a = container.Resolve <TestLoggerController>(); a.Update(str); Assert.Equal(str, a.Fetch()); }
public void DuplicateTypeRegistrationThrowsError() { var container = new InfuseContainer(); container.Register <IChat, Chatroom>(LifecycleType.Singleton); container.RegisterSingleton <IPerson, PersonA>(); Assert.Throws <ArgumentException>(() => container.RegisterSingleton <IPerson, PersonB>()); }
public void RegisterTypeWithParametersAndResolve() { var container = new InfuseContainer(); container.Register <IChat, Chatroom>(LifecycleType.Singleton); container.RegisterSingleton <IPerson, PersonA>(); var person = container.Resolve <IPerson>(); Assert.NotNull(person); }
public void EnsureDefaultRegistrationLifecycleIsTransient() { var container = new InfuseContainer(); container.Register <Logger, Logger>(); var logger1 = container.Resolve <Logger>(); var logger2 = container.Resolve <Logger>(); Assert.NotSame(logger1, logger2); }
public void RegisterAsTransientAndResolve() { var container = new InfuseContainer(); container.Register <Logger, Logger>(LifecycleType.Transient); var logger = container.Resolve <Logger>(); Assert.NotNull(logger); Assert.IsType <Logger>(logger); }
public void DuplicateTypeRegistrationOverwritesThePreviousOne() { var container = new InfuseContainer(); container.Register <IChat, Chatroom>(LifecycleType.Singleton); container.RegisterSingleton <IPerson, PersonA>(); container.RegisterSingleton <IPerson, PersonB>(); var person = container.Resolve <IPerson>(); Assert.IsType <PersonB>(person); }
public void SingletonsHasOnlyOneInstancePerContainer() { IContainer container = new InfuseContainer(); container.Register <IChat, Chatroom>(LifecycleType.Singleton); container.RegisterSingleton <IPerson, PersonA>(); string talkMsg = "Hello"; var a = container.Resolve <IPerson>(); var chat = container.Resolve <IChat>(); a.Say(talkMsg); Assert.Equal(talkMsg, chat.Receive()); }
public void TransientDoesNotRegisterAsSingleton_ButManagesSingletonWithinIt() { IContainer container = new InfuseContainer(); container.Register <IChat, Chatroom>(LifecycleType.Singleton); container.RegisterTransient <IPerson, PersonA>(); string talkMsg = "Hello"; var a = container.Resolve <IPerson>(); var b = container.Resolve <IPerson>(); Assert.NotSame(a, b); a.Say(talkMsg); Assert.Equal(talkMsg, b.Listen()); }
public void SingletonsAreSharedBetweenMultipleTransient() { IContainer container = new InfuseContainer(); container.Register <IChat, Chatroom>(LifecycleType.Singleton); container.RegisterTransient <PersonA, PersonA>(); container.RegisterTransient <PersonB, PersonB>(); string talkMsg = "Hello"; var a = container.Resolve <PersonA>(); var b = container.Resolve <PersonB>(); Assert.NotSame(a, b); a.Say(talkMsg); Assert.Equal(talkMsg, b.Listen()); }
public void RegisterTransientTypeWithinASingletonTypeGetsAutoPromotedToSingleton() { IContainer container = new InfuseContainer(); container.RegisterSingleton <IPerson, PersonA>(); container.Register <IChat, Chatroom>(LifecycleType.Transient); string talkMsg = "Hello"; var a = container.Resolve <IPerson>(); var b = container.Resolve <IPerson>(); Assert.Same(a, b); a.Say(talkMsg); Assert.Equal(talkMsg, b.Listen()); }
public void SameTypeMultipleInstances() { IContainer container = new InfuseContainer(); container.Register <IChat, Chatroom>(LifecycleType.Singleton); container.RegisterTransient <IPerson, PersonA>(); container.RegisterTransient <IPerson, PersonB>(); string talkMsg = "Hello"; var a = container.Resolve <IPerson>(); //resole A? var b = container.Resolve <IPerson>(); //resolve B? Assert.NotSame(a, b); a.Say(talkMsg); Assert.Equal(talkMsg, b.Listen()); }