Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }