Exemplo n.º 1
0
        public void DuplicateTypeRegistrationThrowsError()
        {
            var container = new InfuseContainer();

            container.Register <IChat, Chatroom>(LifecycleType.Singleton);
            container.RegisterSingleton <IPerson, PersonA>();


            Assert.Throws <ArgumentException>(() => container.RegisterSingleton <IPerson, PersonB>());
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void RegisterAsSingletonUsingExtensionAndResolve()
        {
            var container = new InfuseContainer();

            container.RegisterSingleton <Logger, Logger>();

            var logger = container.Resolve <Logger>();

            Assert.NotNull(logger);
            Assert.IsType <Logger>(logger);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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());
        }
Exemplo n.º 7
0
        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());
        }