Exemple #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)));
        }
Exemple #2
0
        public void DefaultPolicyUsedWhenSpecificPolicyIsntAvailable()
        {
            PolicyList list          = new PolicyList();
            MockPolicy defaultPolicy = new MockPolicy();

            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            Assert.AreSame(defaultPolicy, list.Get <IBuilderPolicy>(typeof(object), null));
        }
Exemple #3
0
        public void SpecificPolicyOverridesDefaultPolicy()
        {
            PolicyList list           = new PolicyList();
            MockPolicy defaultPolicy  = new MockPolicy();
            MockPolicy specificPolicy = new MockPolicy();

            list.Set <IBuilderPolicy>(specificPolicy, typeof(object), null);
            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            Assert.AreSame(specificPolicy, list.Get <IBuilderPolicy>(typeof(object), null));
        }
Exemple #4
0
        public void CanClearDefaultPolicy()
        {
            PolicyList list          = new PolicyList();
            MockPolicy defaultPolicy = new MockPolicy();

            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            list.ClearDefault <IBuilderPolicy>();

            Assert.IsNull(list.Get <IBuilderPolicy>(typeof(object), null));
        }