예제 #1
0
 public void ChainForNullIdOnTypeWithoutNameMappingDoesNotInvokeMappper()
 {
     builder.BuildUp(null,
                     null,
                     new PolicyList(),
                     strategies.MakeStrategyChain(),
                     NamedTypeBuildKey.Make <TypeWithoutNameMappingAttribute>(),
                     null);
     Assert.IsFalse(MockNameMapper.invoked);
 }
예제 #2
0
 /// <summary>
 /// Run an existing object through the container, and clean it up.
 /// </summary>
 /// <param name="o">The object to tear down.</param>
 public override void Teardown(object o)
 {
     try
     {
         new Builder().TearDown(
             locator,
             lifetimeContainer,
             policies,
             strategies.MakeStrategyChain(),
             o);
     }
     catch (BuildFailedException ex)
     {
         throw new ResolutionFailedException(o.GetType(), null, ex);
     }
 }
예제 #3
0
        protected virtual IStrategyChain CreateStrategyChain()
        {
            StagedStrategyChain <BuilderStage> strategies = new StagedStrategyChain <BuilderStage>();

            Strategies.ForEach(item => strategies.Add(CreateStrategy(item.Type), item.Stage));

            return(strategies.MakeStrategyChain());
        }
 public void TestDeepProfilingExtensionWithEmptyFilter()
 {
     var strategies = new StagedStrategyChain<UnityBuildStage>();
     var mockContext = new Mock<ExtensionContext>();
     mockContext.Setup(c => c.Strategies).Returns(strategies);
     var target = new DeepProfilingExtension(null);
     target.InitializeExtension(mockContext.Object);
     Assert.AreEqual(0, strategies.MakeStrategyChain().Count());
 }
        static EnterpriseLibraryFactory()
        {
            builder = new Builder();
            StagedStrategyChain <BuilderStage> stagedStrategyChain = new StagedStrategyChain <BuilderStage>();

            stagedStrategyChain.AddNew <ConfigurationNameMappingStrategy>(BuilderStage.PreCreation);
            stagedStrategyChain.AddNew <LocatorLookupStrategy>(BuilderStage.PreCreation);
            stagedStrategyChain.AddNew <ConfiguredObjectStrategy>(BuilderStage.PreCreation);
            stagedStrategyChain.AddNew <InstrumentationStrategy>(BuilderStage.PostInitialization);
            strategyChain = stagedStrategyChain.MakeStrategyChain();
        }
예제 #6
0
        public void InnerStrategiesComeBeforeOuterStrategiesInStrategyChain()
        {
            StagedStrategyChain<FakeStage> innerChain = new StagedStrategyChain<FakeStage>();
            StagedStrategyChain<FakeStage> outerChain = new StagedStrategyChain<FakeStage>(innerChain);
            FakeStrategy innerStrategy = new FakeStrategy();
            FakeStrategy outerStrategy = new FakeStrategy();
            innerChain.Add(innerStrategy, FakeStage.Stage1);
            outerChain.Add(outerStrategy, FakeStage.Stage1);

            IStrategyChain chain = outerChain.MakeStrategyChain();

            AssertOrder(chain, innerStrategy, outerStrategy);
        }
        public void InnerStrategiesComeBeforeOuterStrategiesInStrategyChain()
        {
            StagedStrategyChain <FakeStage> innerChain = new StagedStrategyChain <FakeStage>();
            StagedStrategyChain <FakeStage> outerChain = new StagedStrategyChain <FakeStage>(innerChain);
            FakeStrategy innerStrategy = new FakeStrategy();
            FakeStrategy outerStrategy = new FakeStrategy();

            innerChain.Add(innerStrategy, FakeStage.Stage1);
            outerChain.Add(outerStrategy, FakeStage.Stage1);

            IStrategyChain chain = outerChain.MakeStrategyChain();

            AssertOrder(chain, innerStrategy, outerStrategy);
        }
        public void InitializeAddsReleasingStrategyToContext()
        {
            // Fixture setup
            var strategies = new StagedStrategyChain<UnityBuildStage>();

            var contextStub = new Mock<ExtensionContext> { CallBase = true };
            contextStub.SetupGet(ctx => ctx.Strategies).Returns(strategies);

            var sut = new CacheLifetimeStrategyExtension();
            // Exercise system
            sut.InitializeExtension(contextStub.Object);
            // Verify outcome
            Assert.True(strategies.MakeStrategyChain().OfType<CacheReleasingLifetimeStrategy>().Any());
            // Teardown
        }
예제 #9
0
        public void MultipleChildContainers()
        {
            StagedStrategyChain<FakeStage> innerChain = new StagedStrategyChain<FakeStage>();
            StagedStrategyChain<FakeStage> outerChain = new StagedStrategyChain<FakeStage>(innerChain);
            StagedStrategyChain<FakeStage> superChain = new StagedStrategyChain<FakeStage>(outerChain);

            FakeStrategy innerStrategy = new FakeStrategy();
            FakeStrategy outerStrategy = new FakeStrategy();
            FakeStrategy superStrategy = new FakeStrategy();
            innerChain.Add(innerStrategy, FakeStage.Stage1);
            outerChain.Add(outerStrategy, FakeStage.Stage1);
            superChain.Add(superStrategy, FakeStage.Stage1);

            IStrategyChain chain = superChain.MakeStrategyChain();

            AssertOrder(chain, innerStrategy, outerStrategy, superStrategy);
        }
        public void OrderingAcrossStagesForStrategyChain()
        {
            StagedStrategyChain<FakeStage> innerChain = new StagedStrategyChain<FakeStage>();
            StagedStrategyChain<FakeStage> outerChain = new StagedStrategyChain<FakeStage>(innerChain);
            FakeStrategy innerStage1 = new FakeStrategy();
            FakeStrategy innerStage2 = new FakeStrategy();
            FakeStrategy outerStage1 = new FakeStrategy();
            FakeStrategy outerStage2 = new FakeStrategy();
            innerChain.Add(innerStage1, FakeStage.Stage1);
            innerChain.Add(innerStage2, FakeStage.Stage2);
            outerChain.Add(outerStage1, FakeStage.Stage1);
            outerChain.Add(outerStage2, FakeStage.Stage2);

            IStrategyChain chain = outerChain.MakeStrategyChain();

            AssertOrder(chain, innerStage1, outerStage1, innerStage2, outerStage2);
        }
        public void MultipleChildContainers()
        {
            StagedStrategyChain <FakeStage> innerChain = new StagedStrategyChain <FakeStage>();
            StagedStrategyChain <FakeStage> outerChain = new StagedStrategyChain <FakeStage>(innerChain);
            StagedStrategyChain <FakeStage> superChain = new StagedStrategyChain <FakeStage>(outerChain);

            FakeStrategy innerStrategy = new FakeStrategy();
            FakeStrategy outerStrategy = new FakeStrategy();
            FakeStrategy superStrategy = new FakeStrategy();

            innerChain.Add(innerStrategy, FakeStage.Stage1);
            outerChain.Add(outerStrategy, FakeStage.Stage1);
            superChain.Add(superStrategy, FakeStage.Stage1);

            IStrategyChain chain = superChain.MakeStrategyChain();

            AssertOrder(chain, innerStrategy, outerStrategy, superStrategy);
        }
        public void OrderingAcrossStagesForStrategyChain()
        {
            StagedStrategyChain <FakeStage> innerChain = new StagedStrategyChain <FakeStage>();
            StagedStrategyChain <FakeStage> outerChain = new StagedStrategyChain <FakeStage>(innerChain);
            FakeStrategy innerStage1 = new FakeStrategy();
            FakeStrategy innerStage2 = new FakeStrategy();
            FakeStrategy outerStage1 = new FakeStrategy();
            FakeStrategy outerStage2 = new FakeStrategy();

            innerChain.Add(innerStage1, FakeStage.Stage1);
            innerChain.Add(innerStage2, FakeStage.Stage2);
            outerChain.Add(outerStage1, FakeStage.Stage1);
            outerChain.Add(outerStage2, FakeStage.Stage2);

            IStrategyChain chain = outerChain.MakeStrategyChain();

            AssertOrder(chain, innerStage1, outerStage1, innerStage2, outerStage2);
        }
        public void InitializeAddsReleasingStrategyToContext()
        {
            // Fixture setup
            var strategies = new StagedStrategyChain <UnityBuildStage>();

            var contextStub = new Mock <ExtensionContext> {
                CallBase = true
            };

            contextStub.SetupGet(ctx => ctx.Strategies).Returns(strategies);

            var sut = new CacheLifetimeStrategyExtension();

            // Exercise system
            sut.InitializeExtension(contextStub.Object);
            // Verify outcome
            Assert.True(strategies.MakeStrategyChain().OfType <CacheReleasingLifetimeStrategy>().Any());
            // Teardown
        }
예제 #14
0
        private IStrategyChain GetStrategies()
        {
            IStrategyChain buildStrategies = cachedStrategies;

            if (buildStrategies == null)
            {
                lock (cachedStrategiesLock)
                {
                    if (cachedStrategies == null)
                    {
                        buildStrategies  = strategies.MakeStrategyChain();
                        cachedStrategies = buildStrategies;
                    }
                    else
                    {
                        buildStrategies = cachedStrategies;
                    }
                }
            }
            return(buildStrategies);
        }
예제 #15
0
 public object Get(Type typeToBuild)
 {
     return(builder.BuildUp(locator, lifetime, policies, strategies.MakeStrategyChain(), typeToBuild, null));
 }