public void PostTearDownRemovesFromAllLifetimePolicies()
        {
            // Fixture setup
            var lifetimeMocks = Enumerable.Range(1, 3).Select(i => new Mock<CacheLifetimeManager>(new Mock<ILease>().Object)).ToList();

            var lifetimeContainer = new LifetimeContainer();
            lifetimeMocks.ForEach(m => lifetimeContainer.Add(m.Object));

            var contextStub = new Mock<IBuilderContext>();
            contextStub.SetupGet(ctx => ctx.Lifetime).Returns(lifetimeContainer);

            var sut = new CacheReleasingLifetimeStrategy();
            // Exercise system
            sut.PostTearDown(contextStub.Object);
            // Verify outcome
            lifetimeMocks.ForEach(m => m.Verify(lp => lp.RemoveValue()));
            // Teardown
        }
Ejemplo n.º 2
0
        private void InitializeBuilderState()
        {
            registeredNames = new NamedTypesRegistry(ParentNameRegistry);
            extensions = new List<UnityContainerExtension>();

            locator = new Locator(ParentLocator);
            lifetimeContainer = new LifetimeContainer();
            strategies = new StagedStrategyChain<UnityBuildStage>(ParentStrategies);
            buildPlanStrategies = new StagedStrategyChain<UnityBuildStage>(ParentBuildPlanStrategies);
            policies = new PolicyList(ParentPolicies);

            cachedStrategies = null;
            cachedStrategiesLock = new object();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Dispose this container instance.
        /// </summary>
        /// <remarks>
        /// This class doesn't have a finalizer, so <paramref name="disposing"/> will always be true.</remarks>
        /// <param name="disposing">True if being called from the IDisposable.Dispose
        /// method, false if being called from a finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (lifetimeContainer != null)
                {
                    lifetimeContainer.Dispose();
                    lifetimeContainer = null;

                    if (parent != null && parent.lifetimeContainer != null)
                    {
                        parent.lifetimeContainer.Remove(this);
                    }
                }
                foreach(IDisposable disposableExtension in Sequence.OfType<IDisposable>(extensions))
                {
                    disposableExtension.Dispose();
                }
                extensions.Clear();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Dispose this container instance.
        /// </summary>
        /// <remarks>
        /// This class doesn't have a finalizer, so <paramref name="disposing"/> will always be true.</remarks>
        /// <param name="disposing">True if being called from the IDisposable.Dispose
        /// method, false if being called from a finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (lifetimeContainer != null)
                {
                    lifetimeContainer.Dispose();
                    lifetimeContainer = null;

                    if (parent != null && parent.lifetimeContainer != null)
                    {
                        parent.lifetimeContainer.Remove(this);
                    }
                }

                extensions.OfType<IDisposable>().ForEach(ex => ex.Dispose());
                extensions.Clear();
            }
        }