Ejemplo n.º 1
0
        public void CreationPolicyWillRecordSingletonsUsingLocalLifetimeContainerOnly()
        {
            BuilderStrategyChain chain = new BuilderStrategyChain();

            chain.Add(new CreationStrategy());

            Locator           parentLocator = new Locator();
            LifetimeContainer container     = new LifetimeContainer();

            parentLocator.Add(typeof(ILifetimeContainer), container);

            Locator childLocator = new Locator(parentLocator);

            PolicyList policies = new PolicyList();

            policies.SetDefault <ICreationPolicy>(new DefaultCreationPolicy());
            policies.SetDefault <ISingletonPolicy>(new SingletonPolicy(true));

            BuilderContext ctx = new BuilderContext(chain, childLocator, policies);

            object obj = ctx.HeadOfChain.BuildUp(ctx, typeof(object), null, null);

            Assert.IsNotNull(obj);
            Assert.IsNull(childLocator.Get(new DependencyResolutionLocatorKey(typeof(object), null)));
        }
        private static IPlanBuilderPolicy CreatePlanBuilder(MockReturnExistingPlanBuilderStrategy mockPlanBuilderStrategy)
        {
            BuilderStrategyChain chain = new BuilderStrategyChain();
            chain.Add(mockPlanBuilderStrategy);

            PolicyList policies = new PolicyList();

            return new DynamicMethodPlanBuilderPolicy(chain, policies);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a strategy chain based on the strategies in the list. Useful for
        /// build operations.
        /// </summary>
        /// <returns>The new strategy chain.</returns>
        public IBuilderStrategyChain MakeStrategyChain()
        {
            lock (lockObject)
            {
                BuilderStrategyChain result = new BuilderStrategyChain();

                foreach (TStageEnum stage in stageValues)
                {
                    result.AddRange(stages[stage]);
                }

                return(result);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a reverse strategy chain based on the strategies in the list. Useful
        /// for unbuild operations (which run strategies in reverse of build operations).
        /// </summary>
        /// <returns>The new strategy chain.</returns>
        public IBuilderStrategyChain MakeReverseStrategyChain()
        {
            lock (lockObject)
            {
                List <IBuilderStrategy> tempList = new List <IBuilderStrategy>();
                foreach (TStageEnum stage in stageValues)
                {
                    tempList.AddRange(stages[stage]);
                }

                tempList.Reverse();

                BuilderStrategyChain result = new BuilderStrategyChain();
                result.AddRange(tempList);
                return(result);
            }
        }
        private static IPlanBuilderPolicy CreatePlanBuilder(PolicyList innerPolicies)
        {
            BuilderStrategyChain chain = new BuilderStrategyChain();
            chain.Add(new CallConstructorStrategy());

            return new DynamicMethodPlanBuilderPolicy(chain, innerPolicies);
        }
        public void CreationPolicyWillRecordSingletonsUsingLocalLifetimeContainerOnly()
        {
            BuilderStrategyChain chain = new BuilderStrategyChain();
            chain.Add(new CreationStrategy());

            Locator parentLocator = new Locator();
            LifetimeContainer container = new LifetimeContainer();
            parentLocator.Add(typeof (ILifetimeContainer), container);

            Locator childLocator = new Locator(parentLocator);

            PolicyList policies = new PolicyList();
            policies.SetDefault<ICreationPolicy>(new DefaultCreationPolicy());
            policies.SetDefault<ISingletonPolicy>(new SingletonPolicy(true));

            BuilderContext ctx = new BuilderContext(chain, childLocator, policies);

            object obj = ctx.HeadOfChain.BuildUp(ctx, typeof (object), null, null);

            Assert.IsNotNull(obj);
            Assert.IsNull(childLocator.Get(new DependencyResolutionLocatorKey(typeof (object), null)));
        }