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(PolicyList innerPolicies)
		{
			BuilderStrategyChain chain = new BuilderStrategyChain();
			chain.Add(new CallConstructorStrategy());


			return new DynamicMethodPlanBuilderPolicy(chain, innerPolicies);
		}
        private static IPlanBuilderPolicy CreatePlanBuilder(MockReturnExistingPlanBuilderStrategy mockPlanBuilderStrategy)
        {
            BuilderStrategyChain chain = new BuilderStrategyChain();

            chain.Add(mockPlanBuilderStrategy);

            PolicyList policies = new PolicyList();

            return(new DynamicMethodPlanBuilderPolicy(chain, policies));
        }
Esempio n. 4
0
        private static IPlanBuilderPolicy CreatePlanBuilder()
        {
            BuilderStrategyChain chain = new BuilderStrategyChain();

            chain.Add(new CallConstructorStrategy());
            chain.Add(new SetPropertiesStrategy());
            chain.Add(new CallMethodsStrategy());

            PolicyList policies = new PolicyList();

            policies.SetDefault <IConstructorChooserPolicy>(new AttributeBasedConstructorChooser());
            policies.SetDefault <IPropertyChooserPolicy>(new AttributeBasedPropertyChooser());
            policies.SetDefault <IMethodChooserPolicy>(new AttributeBasedMethodChooser());

            return(new DynamicMethodPlanBuilderPolicy(chain, policies));
        }
Esempio n. 5
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)));
        }