Example #1
0
        public void TestParameterDependency()
        {
            Locator           locator   = new Locator();
            LifetimeContainer container = new LifetimeContainer();

            locator.Add(typeof(ILifetimeContainer), container);
            WCSFBuilder builder = new WCSFBuilder();

            TestProviderHost.Provider = new MockProvider();

            TestParameterDependency obj = builder.BuildUp <TestParameterDependency>(locator, "foo", null);

            Assert.IsNotNull(obj.Provider);
            Assert.AreSame(TestProviderHost.Provider, obj.Provider);
        }
        public void TestBuildWithParameterDependency()
        {
            Locator           locator   = new Locator();
            LifetimeContainer container = new LifetimeContainer();

            locator.Add(typeof(ILifetimeContainer), container);
            WCSFBuilder builder = new WCSFBuilder();

            builder.Policies.SetDefault <ISingletonPolicy>(new SingletonPolicy(true));

            TestableRootCompositionContainer compositionContainer = new TestableRootCompositionContainer(builder);

            locator.Add(new DependencyResolutionLocatorKey(typeof(CompositionContainer), null), compositionContainer);
            ITestService service = compositionContainer.Services.AddNew <TestService, ITestService>();

            TestParameterDependency builtObject =
                builder.BuildUp(locator, typeof(TestParameterDependency), Guid.NewGuid().ToString(), null) as
                TestParameterDependency;

            Assert.IsNotNull(builtObject);
            Assert.IsNotNull(builtObject.TestService);
            Assert.AreEqual(service, builtObject.TestService);
        }