Пример #1
0
        public void TestSupplyOverridesName()
        {
            binder.Bind <ClassToBeInjected> ().To <ClassToBeInjected> ().SupplyTo <HasANamedInjection> ();
            binder.Bind <ClassToBeInjected> ().To <ClassToBeInjected> ().ToName("CapnJack").SupplyTo <HasANamedInjection2> ();
            binder.Bind <HasANamedInjection>().To <HasANamedInjection> ();
            binder.Bind <HasANamedInjection2>().To <HasANamedInjection2> ();

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

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

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

            Assert.IsInstanceOf <ClassToBeInjected> (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 TestComplexSupplyBinding()
        {
            binder.Bind <ClassToBeInjected> ().To <ClassToBeInjected> ().ToName(SomeEnum.ONE);
            binder.Bind <ClassToBeInjected>().To <ExtendsClassToBeInjected>()
            .SupplyTo <HasANamedInjection> ()
            .SupplyTo <ConstructorInjectsClassToBeInjected>();
            binder.Bind <HasANamedInjection>().To <HasANamedInjection> ();
            binder.Bind <HasANamedInjection2>().To <HasANamedInjection2> ();
            binder.Bind <ConstructorInjectsClassToBeInjected>().To <ConstructorInjectsClassToBeInjected> ();

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

            Assert.IsInstanceOf <ExtendsClassToBeInjected> (instance.injected);
            Assert.IsInstanceOf <ExtendsClassToBeInjected> (instance2.injected);
            Assert.IsNotInstanceOf <ExtendsClassToBeInjected> (instance3.injected);

            binder.Unsupply <ClassToBeInjected, HasANamedInjection> ();

            HasANamedInjection instance4 = binder.GetInstance <HasANamedInjection> ();

            Assert.IsNotInstanceOf <ExtendsClassToBeInjected> (instance4.injected);
        }