Exemple #1
0
        public void InitializeToNewIsCalledOnInstall()
        {
            var eventCounter = new InjectEventCounter();

            var container = Container.Create();

            container.Bind <InjectEventCounter>().ToConstant(eventCounter).AsCached().OnInstall();
            container.Bind <InitializationAware>().ToNew().AsCached().OnInstall();

            Assert.Equal(0, eventCounter.Initialize);

            var resolver = container.Install();

            Assert.Equal(1, eventCounter.Initialize);
        }
Exemple #2
0
        public void InitializeToConstantIsCalledOnInstall_EmptyParent()
        {
            var eventCounter        = new InjectEventCounter();
            var initializationAware = new InitializationAware();

            var container = Container.Create(TestHelper.CreateEmptyContainer(true));

            container.Bind <InjectEventCounter>().ToConstant(eventCounter).AsCached().OnInstall();
            container.Bind <InitializationAware>().ToConstant(initializationAware).AsCached().OnInstall();

            Assert.Equal(0, eventCounter.Initialize);

            var resolver = container.Install();

            Assert.Equal(1, eventCounter.Initialize);
        }
Exemple #3
0
        public void InitializeToNewAsTransientIsCalledOnExplicitCreate()
        {
            var eventCounter = new InjectEventCounter();

            var container = Container.Create();

            container.Bind <InjectEventCounter>().ToConstant(eventCounter).AsCached().OnInstall();
            container.Bind <InitializationAware>().ToNew().AsTransient().OnRequest();

            var resolver = container.Install();

            Assert.Equal(0, eventCounter.Initialize);

            var factory = resolver.Get <IFactory <InitializationAware> >();

            Assert.Equal(0, eventCounter.Initialize);

            var initializationAware = factory.Create();

            Assert.Equal(1, eventCounter.Initialize);
        }