示例#1
0
        static void Main(string[] args)
        {
            IAnimal cat = AnimalFactory.Create(0);

            cat.Bark();

            IAnimal dog = AnimalFactory.Create(1);

            dog.Bark();
        }
示例#2
0
        public void BasicTest_LoadModule()
        {
            DependencyResolver.Container.LoadModules(new Module());

            ParameterList args = new ParameterList();

            args[typeof(IAnimal), "name"] = "BIG POCHI";

            IAnimal animal = DependencyResolver.Get(typeof(IAnimal), args) as IAnimal;

            animal.Bark();
            animal.Wark();

            Assert.AreEqual(typeof(BigDog), animal.GetType());
            Assert.AreEqual(args[typeof(IAnimal), "name"].ToString(), (animal as BigDog).Name);
        }
示例#3
0
        public void BasicTest_PropertiesAutowired_IsUsingConstructor()
        {
            DependencyResolver.Container.Set(typeof(IBehavior)).To(typeof(Behavior2)).PropertiesAutowired();

            DependencyResolver.Container.Set(typeof(BigDog)).To(typeof(BigDog));
            DependencyResolver.Container.Set(typeof(BigDog)).UsingConstructor(typeof(string)).PropertiesAutowired();

            ParameterList args = new ParameterList();

            args[typeof(BigDog), "name"] = "BIG POCHI";

            IAnimal animal = DependencyResolver.Get(typeof(BigDog), args) as IAnimal;

            animal.Bark();
            animal.Wark();

            Assert.AreEqual(typeof(BigDog), animal.GetType());
            Assert.AreEqual(args[typeof(BigDog), "name"].ToString(), (animal as BigDog).Name);
        }
示例#4
0
        public void BasicTest_ConstructorInjection()
        {
            ParameterList args = new ParameterList();

            args[typeof(IAnimal), "name"] = "POCHI";

            IAnimal animal = DependencyResolver.Get(typeof(IAnimal), args) as IAnimal;

            animal.Bark();
            animal.Wark();

            Assert.AreEqual(typeof(Dog), animal.GetType());
            Assert.AreEqual(args[typeof(IAnimal), "name"].ToString(), (animal as Dog).Name);

            args[typeof(IAnimal), "behavior"] = new Behavior2();

            animal = DependencyResolver.Get(typeof(IAnimal), args) as IAnimal;

            Assert.AreEqual(args[typeof(IAnimal), "behavior"], (animal as Dog).GetBehavior());
        }
示例#5
0
        public void BasicTest_Remove_IsSingleton()
        {
            DependencyResolver.Container.Set(typeof(Dog)).Remove();
            DependencyResolver.Container.Set(typeof(IAnimal)).To(typeof(Dog));
            DependencyResolver.Container.Set(typeof(IAnimal)).Singleton();

            ParameterList args = new ParameterList();

            args[typeof(IAnimal), "name"] = "POCHI";

            IAnimal animal = DependencyResolver.Get(typeof(IAnimal), args) as IAnimal;

            animal.Bark();
            animal.Wark();

            IAnimal animal2 = DependencyResolver.Get(typeof(IAnimal), args) as IAnimal;

            animal2.Bark();
            animal2.Wark();

            Assert.AreEqual(animal, animal2);
        }
示例#6
0
 public void UseAnimal(IAnimal animal)
 {
     animal.Bark(_box);
 }