public void Explicitly_registered_factory_is_tracked()
        {
            Container.Register(Component.For <Func <A> >().AsFactory());

            ReferenceTracker
            .Track(() => Container.Resolve <Func <A> >())
            .AssertStillReferenced();
        }
Exemplo n.º 2
0
        public void Factory_is_tracked_by_the_container()
        {
            Container.Register(Component.For <IDummyComponentFactory>().AsFactory());

            ReferenceTracker
            .Track(() => Container.Resolve <IDummyComponentFactory>())
            .AssertStillReferenced();
        }
        public void TransientReferencesAreNotHeldByContainer()
        {
            Kernel.Register(Component.For <EmptyClass>().LifeStyle.Transient);

            ReferenceTracker
            .Track(() => Kernel.Resolve <EmptyClass>())
            .AssertNoLongerReferenced();
        }
Exemplo n.º 4
0
        public void Managed_externally_factory_component_transient_is_not_tracked_by_the_container()
        {
            Kernel.Register(Component.For <DisposableComponent>()
                            .LifeStyle.Transient
                            .UsingFactoryMethod(() => new DisposableComponent(), managedExternally: true));

            ReferenceTracker
            .Track(() => Kernel.Resolve <DisposableComponent>())
            .AssertNoLongerReferenced();
        }
Exemplo n.º 5
0
        public void Initializable_components_are_not_tracked()
        {
            Container.Register(Component.For <ISimpleService>()
                               .ImplementedBy <SimpleServiceInitializable>()
                               .LifeStyle.Transient);

            ReferenceTracker
            .Track(() => Container.Resolve <ISimpleService>())
            .AssertNoLongerReferenced();
        }
        public void Factory_obeys_release_policy_tracking()
        {
            Container.Register(Component.For <DisposableFoo>().LifeStyle.Transient,
                               Component.For <UsesDisposableFooDelegate>().LifeStyle.Transient);

            var dependsOnFoo = Container.Resolve <UsesDisposableFooDelegate>();

            ReferenceTracker
            .Track(() => dependsOnFoo.GetFoo())
            .AssertStillReferenced();
        }
Exemplo n.º 7
0
        public void Typed_factory_obeys_release_policy_tracking()
        {
            Container.Register(
                Component.For <INonDisposableFactory>().LifeStyle.Transient.AsFactory(),
                Component.For <DisposableComponent>().LifeStyle.Transient);
            var factory = Container.Resolve <INonDisposableFactory>();

            ReferenceTracker
            .Track(() => factory.Create())
            .AssertStillReferenced();
        }
Exemplo n.º 8
0
        public void Transient_depending_on_scoped_component_is_not_tracked_by_the_container()
        {
            Container.Register(Component.For <DisposableFoo>().LifeStyle.Scoped(),
                               Component.For <UsesDisposableFoo>().LifeStyle.Transient);

            using (Container.BeginScope())
            {
                ReferenceTracker
                .Track(() => Container.Resolve <UsesDisposableFoo>())
                .AssertNoLongerReferenced();
            }
        }
        public void Factory_obeys_release_policy_non_tracking()
        {
#pragma warning disable 612,618
            Container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();
#pragma warning restore 612,618
            Container.Register(Component.For <DisposableFoo>().LifeStyle.Transient,
                               Component.For <UsesDisposableFooDelegate>().LifeStyle.Transient);
            var dependsOnFoo = Container.Resolve <UsesDisposableFooDelegate>();

            ReferenceTracker
            .Track(() => dependsOnFoo.GetFoo())
            .AssertNoLongerReferenced();
        }
Exemplo n.º 10
0
        public void Typed_factory_lets_go_of_component_reference_on_release()
        {
            Container.Register(
                Component.For <IDisposableFactory>().LifeStyle.Transient.AsFactory(),
                Component.For <DisposableComponent>().LifeStyle.Transient);
            var factory = Container.Resolve <IDisposableFactory>();

            var tracker = ReferenceTracker.Track(() => factory.Create());

            tracker.AssertStillReferencedAndDo(component => factory.Destroy(component));

            tracker.AssertNoLongerReferenced();
        }
Exemplo n.º 11
0
        public void Component_released_via_factory_is_not_tracked()
        {
            Container.Register(
                Component.For <INonDisposableFactory>().LifeStyle.Transient.AsFactory(),
                Component.For <DisposableComponent>().LifeStyle.Transient);

            var factory = Container.Resolve <INonDisposableFactory>();

            var tracker = ReferenceTracker.Track(() => factory.Create());

            tracker.AssertStillReferencedAndDo(component => factory.LetGo(component));

            tracker.AssertNoLongerReferenced();
        }
Exemplo n.º 12
0
        public void Component_released_out_of_band_is_STILL_tracked()
        {
            Container.Register(
                Component.For <INonDisposableFactory>().LifeStyle.Transient.AsFactory(),
                Component.For <DisposableComponent>().LifeStyle.Transient);

            var factory = Container.Resolve <INonDisposableFactory>();

            var tracker = ReferenceTracker.Track(() => factory.Create());

            tracker.AssertStillReferencedAndDo(component => Container.Release(component));

            tracker.AssertStillReferenced();
        }
        public void Factory_does_not_reference_components_after_they_are_released()
        {
            DisposableFoo.ResetDisposedCount();

            Container.Register(Component.For <DisposableFoo>().LifeStyle.Transient,
                               Component.For <UsesDisposableFooDelegate>().LifeStyle.Transient);
            var dependsOnFoo = Container.Resolve <UsesDisposableFooDelegate>();

            var tracker = ReferenceTracker.Track(() => dependsOnFoo.GetFoo());

            Assert.AreEqual(0, DisposableFoo.DisposedCount);
            Container.Release(dependsOnFoo);
            Assert.AreEqual(1, DisposableFoo.DisposedCount);

            tracker.AssertNoLongerReferenced();
        }
Exemplo n.º 14
0
        public void Release_doesnt_stop_tracking_component_singleton_until_container_is_disposed()
        {
            DisposableFoo.ResetDisposedCount();
            container.Register(Singleton <DisposableFoo>());

            var tracker = ReferenceTracker.Track(() => container.Resolve <DisposableFoo>());

            tracker.AssertStillReferencedAndDo(foo => container.Release(foo));

            tracker.AssertStillReferenced();
            Assert.AreEqual(0, DisposableFoo.DisposedCount);

            container.Dispose();

            tracker.AssertNoLongerReferenced();
            Assert.AreEqual(1, DisposableFoo.DisposedCount);
        }
Exemplo n.º 15
0
        public void Disposable_singleton_dependency_of_transient_open_generic_is_disposed()
        {
            DisposableFoo.ResetDisposedCount();
            Container.Register(
                Component.For(typeof(GenericComponent <>)).LifeStyle.Transient,
                Component.For <DisposableFoo>().LifeStyle.Singleton
                );

            var tracker = ReferenceTracker
                          .Track(() =>
            {
                var depender = Container.Resolve <GenericComponent <DisposableFoo> >();
                return(depender.Value);
            });

            Container.Dispose();

            Assert.AreEqual(1, DisposableFoo.DisposedCount);
            tracker.AssertNoLongerReferenced();
        }
Exemplo n.º 16
0
        public void Typed_factory_obeys_release_policy_non_tracking()
        {
#pragma warning disable 612,618
            Container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();
#pragma warning restore 612,618
            Container.Register(
                Component.For <INonDisposableFactory>().LifeStyle.Transient.AsFactory(),
                Component.For <DisposableComponent>().LifeStyle.Transient);

            var factory = Container.Resolve <INonDisposableFactory>();

            ReferenceTracker
            .Track(() =>
            {
                var component = factory.Create();
                Container.Release(component);
                return(component);
            })
            .AssertNoLongerReferenced();
        }