コード例 #1
0
        public void eject_with_custom_lifecycle()
        {
            CustomLifecycle.Cache.DisposeAndClear();

            var customLifecycle = new CustomLifecycle();

            var container = new Container(x =>
            {
                x.For <DisposedGuy>().LifecycleIs(customLifecycle).AddInstances(guys =>
                {
                    guys.Type <DisposedGuy>().Named("A");
                    guys.Type <DisposedGuy>().Named("B");
                    guys.Type <DisposedGuy>().Named("C");
                });
            });

            // Fetch all the singleton objects
            var guyA = container.GetInstance <DisposedGuy>("A");
            var guyB = container.GetInstance <DisposedGuy>("B");
            var guyC = container.GetInstance <DisposedGuy>("C");

            container.Model.For <DisposedGuy>().EjectAndRemove("A");

            guyA.WasDisposed.ShouldBeTrue();

            container.Model.EjectAndRemove <DisposedGuy>();

            guyB.WasDisposed.ShouldBeTrue();
            guyC.WasDisposed.ShouldBeTrue();

            // And now the container no longer has any
            // registrations for DisposedGuy
            container.GetAllInstances <DisposedGuy>()
            .Any().ShouldBeFalse();
        }
コード例 #2
0
        public void eject_with_custom_lifecycle()
        {
            CustomLifecycle.Cache.DisposeAndClear();

            var customLifecycle = new CustomLifecycle();

            var container = new Container(x =>
            {
                x.For<DisposedGuy>().LifecycleIs(customLifecycle).AddInstances(guys =>
                {
                    guys.Type<DisposedGuy>().Named("A");
                    guys.Type<DisposedGuy>().Named("B");
                    guys.Type<DisposedGuy>().Named("C");
                });
            });

            // Fetch all the singleton objects
            var guyA = container.GetInstance<DisposedGuy>("A");
            var guyB = container.GetInstance<DisposedGuy>("B");
            var guyC = container.GetInstance<DisposedGuy>("C");

            container.Model.For<DisposedGuy>().EjectAndRemove("A");

            guyA.WasDisposed.ShouldBeTrue();

            container.Model.EjectAndRemove<DisposedGuy>();

            guyB.WasDisposed.ShouldBeTrue();
            guyC.WasDisposed.ShouldBeTrue();

            // And now the container no longer has any
            // registrations for DisposedGuy
            container.GetAllInstances<DisposedGuy>()
                .Any().ShouldBeFalse();
        }