UsesDefaultLifetimeManagerOf() public méthode

public UsesDefaultLifetimeManagerOf ( ILifetimeManager lifetimeManager ) : IContainerFluent
lifetimeManager ILifetimeManager
Résultat IContainerFluent
        public void CanSetDefaultLifetimeManagerToAlwaysNew()
        {
            using (var iocContainer = new IocContainer())
            {
                var lifetime = new AlwaysNewLifetime();
                iocContainer.UsesDefaultLifetimeManagerOf(lifetime);

                Verify.That(iocContainer.DefaultLifetimeManager).IsTheSameObjectAs(lifetime);
            }
        }
Exemple #2
0
        void SettingTheDefaultContainerLifetime()
        {
            // create the container.  Only done once in Application_Start
            IocContainer iocContainer = new IocContainer();

            // create a lifetime manager to use as default
            ILifetimeManager lifetimeManager = new LifetimeManagers.RequestLifetime();

            // set the default lifetime manager
            iocContainer.UsesDefaultLifetimeManagerOf(lifetimeManager);
        }
        public void AlwayNewLifetimeManagerAlwaysReturnsNewInstance()
        {
            using (var iocContainer = new IocContainer())
            {
                var lifetime = new AlwaysNewLifetime();
                iocContainer.UsesDefaultLifetimeManagerOf(lifetime);
                iocContainer.Register<IFoo>(c => new Foo1());

                var foo1 = iocContainer.Resolve<IFoo>();
                var foo2 = iocContainer.Resolve<IFoo>();
                var foo3 = iocContainer.Resolve<IFoo>();

                Verify.That(foo1).IsAnInstanceOfType(typeof(IFoo))
                            .IsNotTheSameObjectAs(foo2)
                            .IsNotTheSameObjectAs(foo3);

                Verify.That(foo2).IsAnInstanceOfType(typeof(IFoo))
                            .IsNotTheSameObjectAs(foo3);

                Verify.That(foo3).IsAnInstanceOfType(typeof(IFoo));
            }
        }