コード例 #1
0
        public void AsyncScopedLifestyleDispose_WithTransientRegisteredForDisposal_DisposesThatInstance()
        {
            // Arrange
            DisposableCommand transientInstanceToDispose = null;

            var container = new Container();

            container.Options.EnableAutoVerification = false;

            var lifestyle = new AsyncScopedLifestyle();

            container.Register <DisposableCommand>();

            container.RegisterInitializer <DisposableCommand>(command =>
            {
                lifestyle.RegisterForDisposal(container, command);
            });

            var scope = AsyncScopedLifestyle.BeginScope(container);

            try
            {
                transientInstanceToDispose = container.GetInstance <DisposableCommand>();
            }
            finally
            {
                // Act
                scope.Dispose();
            }

            // Assert
            Assert.IsTrue(transientInstanceToDispose.HasBeenDisposed);
        }