コード例 #1
0
        public void RegisterWithClassNotImplementsInterface()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(IClass));
            di.Register(typeof(MyClass2), typeof(IClass3));
        }
コード例 #2
0
        public void RegisterTwoTimesToInterface()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(IClass));
            di.Register(typeof(MyClass), typeof(IClass));
        }
コード例 #3
0
        public void RegisterTwoTimesToItself()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass));
            di.Register(typeof(MyClass));
        }
コード例 #4
0
        public void InjectionFailDependencyNotFound()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(IClass));
            di.Register(typeof(MyClass3), typeof(IClass3));

            TestClass testClass = di.CallCtor(typeof(TestClass)) as TestClass;
        }
コード例 #5
0
        public void InjectionGood()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(IClass));
            di.Register(typeof(MyClass2), typeof(IClass2));

            TestClass testClass = di.CallCtor(typeof(TestClass)) as TestClass;

            Assert.AreEqual(true, testClass.IsGood);
        }
コード例 #6
0
        public void PropertyInjectionGood()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(IClass));
            di.Register(typeof(MyClass2), typeof(IClass2));

            TestClass2 testClass = di.CreateAndPropInjection(typeof(TestClass2)) as TestClass2;

            Assert.AreEqual(true, testClass.Property1.IsEnabled);
            Assert.AreEqual(true, testClass.Property2.IsEnabled);
        }
コード例 #7
0
        public void RegisterAndResolveTwoClassesToInterface()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(IClass));
            di.Register(typeof(MyClass2), typeof(IClass2));

            IClass  iClass  = di.Resolve(typeof(MyClass), typeof(IClass)) as MyClass;
            IClass2 iClass2 = di.Resolve(typeof(MyClass2), typeof(IClass2)) as MyClass2;

            Assert.AreEqual(true, iClass.IsEnabled);
            Assert.AreEqual(true, iClass2.IsEnabled);
        }
コード例 #8
0
        public void RegisterAndResolveToItself()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass));

            MyClass myClass = di.Resolve(typeof(MyClass)) as MyClass;

            Assert.AreEqual(true, myClass.IsEnabled);
        }
コード例 #9
0
        public void RegisterAndResolveWithNotExistedInterface()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(IClass));

            IClass iClass = di.Resolve(typeof(MyClass), typeof(IClass2)) as MyClass;

            Assert.AreEqual(null, iClass);
        }
コード例 #10
0
        public void RegisterAndResolveWithKey()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(IClass), "key");

            IClass iClass = di.Resolve(typeof(MyClass), "key") as MyClass;

            Assert.AreEqual(true, iClass.IsEnabled);
        }
コード例 #11
0
        public void InvalidInterfaceTypeTest()
        {
            SimpleDependencyInjector di = new SimpleDependencyInjector();

            di.Register(typeof(MyClass), typeof(MyClass));
        }