예제 #1
0
        public void Should_Call_Dispose_Of_Transient_Dependency_When_Object_Is_Released()
        {
            LocalIocManager.Register <TestSimpleDisposableObject>(DependencyLifeStyle.Transient);
            var obj = LocalIocManager.Resolve <TestSimpleDisposableObject>();

            LocalIocManager.Release(obj);

            obj.DisposeCount.ShouldBe(1);
        }
예제 #2
0
        public void ShouldAutomaticallyReleaseResolvedDependenciesWhenInjectedClassReleased()
        {
            //Arrange
            LocalIocManager.Register <IScopedIocResolver, ScopedIocResolver>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <MyDependency>(DependencyLifeStyle.Transient);
            LocalIocManager.Register <MyMainClass>(DependencyLifeStyle.Transient);

            //Act
            var mainClass  = LocalIocManager.Resolve <MyMainClass>();
            var dependency = mainClass.CreateDependency();

            dependency.IsDisposed.ShouldBeFalse();
            LocalIocManager.Release(mainClass);

            //Assert
            dependency.IsDisposed.ShouldBeTrue();
        }