コード例 #1
0
        public void InjectProperties_UnknownClassWithPropertyDependencyRegisteredAsInstance_InjectsPropertyDependencies()
        {
            var container = CreateContainer();

            container.RegisterInstance <IBar>(new Bar());
            var fooWithProperyDependency = new FooWithPropertyDependency();

            var result = (FooWithPropertyDependency)container.InjectProperties(fooWithProperyDependency);

            Assert.IsAssignableFrom <Bar>(result.Bar);
        }
コード例 #2
0
        public void InjectProperties_KnownClassWithPropertyDependency_InjectsPropertyDependencies()
        {
            var container = CreateContainer();

            container.Register <FooWithPropertyDependency>();
            container.Register <IBar, Bar>();
            var fooWithProperyDependency = new FooWithPropertyDependency();

            var result = (FooWithPropertyDependency)container.InjectProperties(fooWithProperyDependency);

            Assert.IsAssignableFrom <Bar>(result.Bar);
        }
コード例 #3
0
        public void InjectProperties_FuncFactory_InjectsPropertyDependencies()
        {
            var container = CreateContainer();

            container.Register <IBar, Bar>();
            container.Register <IBar, AnotherBar>("AnotherBar");
            container.Register(f => new FooWithPropertyDependency()
            {
                Bar = f.GetInstance <IBar>("AnotherBar")
            });
            var fooWithProperyDependency = new FooWithPropertyDependency();

            var result = (FooWithPropertyDependency)container.InjectProperties(fooWithProperyDependency);

            Assert.IsAssignableFrom <Bar>(result.Bar);
        }