UsesDefaultLifetimeManagerOf() public method

public UsesDefaultLifetimeManagerOf ( ILifetimeManager lifetimeManager ) : IContainerFluent
lifetimeManager ILifetimeManager
return IContainerFluent
Ejemplo n.º 1
0
        public void CanSetDefaultLifetimeManagerToAlwaysNew()
        {
            using (var iocContainer = new IocContainer())
            {
                var lifetime = new AlwaysNewLifetime();
                iocContainer.UsesDefaultLifetimeManagerOf(lifetime);

                Verify.That(iocContainer.DefaultLifetimeManager).IsTheSameObjectAs(lifetime);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        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));
            }
        }