示例#1
0
        public IocFactory(IUnityContainer container)
        {
            IValueLookup lookup = new CompositeValueLookup(new InterfaceFactoryValueLookup((type, name) => container.Resolve(type)));

            beethovenFactory = new BeethovenFactory(
                new DefaultProperty()
                .ValueLookup(lookup)
                .SetterGetter());
            container.RegisterFactory <ICompany>(CreateInstance);
            container.RegisterFactory <ICompanyInformation>(CreateInformationInstance);
        }
        public void AutoAssignTest4()
        {
            Dictionary <string, object> defaultValues = new Dictionary <string, object>
            {
                { "Name", "The evil company" },
                { "Address", 2460 }
            };
            BeethovenFactory factory = null;
            IValueLookup     lookup  = new CompositeValueLookup(
                new DictionaryValueLookup(defaultValues),
                new InterfaceFactoryValueLookup((type, name) => factory.Generate(type)));

            factory = new BeethovenFactory(
                new DefaultProperty()
                .ValueLookup(lookup)
                .SetterGetter());
            ICompany company = factory.Generate <ICompany>();

            Assert.AreEqual("The evil company", company.Information.Name);
            Assert.AreEqual(null, company.Information.Address);
        }
        public void AutoAssignTest2()
        {
            var defaultValues = new
            {
                Name    = "The evil company",
                Address = "2460 Sunshine road"
            };
            BeethovenFactory factory = null;
            IValueLookup     lookup  = new CompositeValueLookup(
                new AnonymousValueLookup(defaultValues),
                new InterfaceFactoryValueLookup((type, name) => factory.Generate(type)));

            factory = new BeethovenFactory(
                new DefaultProperty()
                .ValueLookup(lookup)
                .SetterGetter());
            ICompany company = factory.Generate <ICompany>();

            Assert.AreEqual("The evil company", company.Information.Name);
            Assert.AreEqual("2460 Sunshine road", company.Information.Address);
        }