Пример #1
0
        public void TestSimpleSupplyBinding()
        {
            binder.Bind <ClassToBeInjected> ().To <ClassToBeInjected> ();
            binder.Bind <ClassToBeInjected> ().To <ExtendsClassToBeInjected> ().ToName(1)
            .SupplyTo <ConstructorInjectsClassToBeInjected>();

            binder.Bind <InjectsClassToBeInjected> ().To <InjectsClassToBeInjected> ();
            binder.Bind <ConstructorInjectsClassToBeInjected> ().To <ConstructorInjectsClassToBeInjected> ();

            InjectsClassToBeInjected            instance1 = binder.GetInstance <InjectsClassToBeInjected> ();
            ConstructorInjectsClassToBeInjected instance2 = binder.GetInstance <ConstructorInjectsClassToBeInjected> ();

            Assert.IsInstanceOf <ClassToBeInjected> (instance1.injected);
            Assert.IsInstanceOf <ClassToBeInjected> (instance2.injected);

            Assert.IsNotInstanceOf <ExtendsClassToBeInjected> (instance1.injected);
            Assert.IsInstanceOf <ExtendsClassToBeInjected> (instance2.injected);
        }
Пример #2
0
        public void TestChainedSupplyBinding()
        {
            binder.Bind <ClassToBeInjected>().To <ExtendsClassToBeInjected>()
            .SupplyTo <HasANamedInjection> ()
            .SupplyTo <ConstructorInjectsClassToBeInjected>()
            .SupplyTo <InjectsClassToBeInjected>();

            binder.Bind <HasANamedInjection>().To <HasANamedInjection> ();
            binder.Bind <ConstructorInjectsClassToBeInjected>().To <ConstructorInjectsClassToBeInjected> ();
            binder.Bind <InjectsClassToBeInjected>().To <InjectsClassToBeInjected> ();

            HasANamedInjection instance = binder.GetInstance <HasANamedInjection> ();
            ConstructorInjectsClassToBeInjected instance2 = binder.GetInstance <ConstructorInjectsClassToBeInjected> ();
            InjectsClassToBeInjected            instance3 = binder.GetInstance <InjectsClassToBeInjected> ();

            Assert.IsInstanceOf <ClassToBeInjected> (instance.injected);
            Assert.IsInstanceOf <ClassToBeInjected> (instance2.injected);
            Assert.IsInstanceOf <ClassToBeInjected> (instance3.injected);
        }
Пример #3
0
        public void TestRuntimeSupplyBindingWithArray()
        {
            string jsonString = "[{\"Bind\":\"strange.unittests.ClassToBeInjected\",\"To\":\"strange.unittests.ExtendsClassToBeInjected\",";

            jsonString += "\"Options\": [\"ToSingleton\",{\"SupplyTo\": [\"strange.unittests.HasANamedInjection\",\"strange.unittests.ConstructorInjectsClassToBeInjected\",\"strange.unittests.InjectsClassToBeInjected\"]}]},";
            jsonString += "{\"Bind\":\"strange.unittests.HasANamedInjection\",\"To\":\"strange.unittests.HasANamedInjection\"},";
            jsonString += "{\"Bind\":\"strange.unittests.ConstructorInjectsClassToBeInjected\",\"To\":\"strange.unittests.ConstructorInjectsClassToBeInjected\"},";
            jsonString += "{\"Bind\":\"strange.unittests.InjectsClassToBeInjected\",\"To\":\"strange.unittests.InjectsClassToBeInjected\"}]";

            binder.ConsumeBindings(jsonString);

            HasANamedInjection instance = binder.GetInstance <HasANamedInjection> ();
            ConstructorInjectsClassToBeInjected instance2 = binder.GetInstance <ConstructorInjectsClassToBeInjected> ();
            InjectsClassToBeInjected            instance3 = binder.GetInstance <InjectsClassToBeInjected> ();

            Assert.IsInstanceOf <ClassToBeInjected> (instance.injected);
            Assert.IsInstanceOf <ClassToBeInjected> (instance2.injected);
            Assert.IsInstanceOf <ClassToBeInjected> (instance3.injected);
        }
Пример #4
0
        public void TestRuntimeSimpleSupplyBinding()
        {
            string jsonString = "[{\"Bind\":\"strange.unittests.ClassToBeInjected\",\"To\":\"strange.unittests.ClassToBeInjected\"},";

            jsonString += "{\"Bind\":\"strange.unittests.ClassToBeInjected\",\"To\":\"strange.unittests.ExtendsClassToBeInjected\",\"ToName\": 1,\"Options\": [{\"SupplyTo\": \"strange.unittests.ConstructorInjectsClassToBeInjected\"}]},";
            jsonString += "{\"Bind\":\"strange.unittests.InjectsClassToBeInjected\",\"To\": \"strange.unittests.InjectsClassToBeInjected\"},";
            jsonString += "{\"Bind\":\"strange.unittests.ConstructorInjectsClassToBeInjected\",\"To\": \"strange.unittests.ConstructorInjectsClassToBeInjected\"}]";

            binder.ConsumeBindings(jsonString);

            InjectsClassToBeInjected            instance1 = binder.GetInstance <InjectsClassToBeInjected> ();
            ConstructorInjectsClassToBeInjected instance2 = binder.GetInstance <ConstructorInjectsClassToBeInjected> ();

            Assert.IsInstanceOf <ClassToBeInjected> (instance1.injected);
            Assert.IsInstanceOf <ClassToBeInjected> (instance2.injected);

            Assert.IsNotInstanceOf <ExtendsClassToBeInjected> (instance1.injected);
            Assert.IsInstanceOf <ExtendsClassToBeInjected> (instance2.injected);
        }
Пример #5
0
        public void TestUnsupplyBinding()
        {
            binder.Bind <ClassToBeInjected> ().To <ExtendsClassToBeInjected> ()
            .ToName("Supplier")
            .SupplyTo <InjectsClassToBeInjected> ();

            binder.Bind <ClassToBeInjected> ().To <ClassToBeInjected> ();

            binder.Bind <InjectsClassToBeInjected>().To <InjectsClassToBeInjected> ();

            InjectsClassToBeInjected instance = binder.GetInstance <InjectsClassToBeInjected> ();

            Assert.IsInstanceOf <ClassToBeInjected> (instance.injected);
            Assert.IsInstanceOf <ExtendsClassToBeInjected> (instance.injected);

            binder.Unsupply <ClassToBeInjected, InjectsClassToBeInjected> ();

            InjectsClassToBeInjected instance2 = binder.GetInstance <InjectsClassToBeInjected> ();

            Assert.IsInstanceOf <ClassToBeInjected> (instance2.injected);
            Assert.IsNotInstanceOf <ExtendsClassToBeInjected> (instance2.injected);
        }