Exemplo n.º 1
0
        public void CanSetDefaultLifetimeManagerToContainerLifetime()
        {
            var lifetime = new ContainerLifetime();
            iocContainer.UsesDefaultLifetimeManagerOf(lifetime);

            Verify.That(iocContainer.DefaultLifetimeManager).IsTheSameObjectAs(lifetime);
        }
Exemplo n.º 2
0
        void SettingTheLifetimeManagerForARegistration()
        {
            // create the container.  Only done once in Application_Start
            IocContainer iocContainer = new IocContainer();

            // create a Container lifetime manager to use for 'singelton' services
            // only one instance will be created and reused for each resolve request.
            ILifetimeManager containerLifetimeManager = new LifetimeManagers.ContainerLifetime();

            iocContainer.Register<IMembershipService>( ioc => new AccountMembershipService(Membership.Provider))
                         .WithLifetimeManager(containerLifetimeManager);

            iocContainer.Register<IFormsAuthenticationService>(ioc => new FormsAuthenticationService())
                        .WithLifetimeManager(containerLifetimeManager);
        }
Exemplo n.º 3
0
        public void ContainerLifetimeManagerAlwaysReturnsSameInstance()
        {
            var lifetime = new ContainerLifetime();
            iocContainer.UsesDefaultLifetimeManagerOf(lifetime);
            iocContainer.Register<IFoo>(c => new Foo1());

            var result1 = iocContainer.Resolve<IFoo>();
            var result2 = iocContainer.Resolve<IFoo>();
            var result3 = iocContainer.Resolve<IFoo>();

            Verify.That(result3).IsNotNull();
            Verify.That(result2).IsNotNull();
            Verify.That(result1).IsNotNull()
                        .IsTheSameObjectAs(result2)
                        .IsTheSameObjectAs(result3);
        }