예제 #1
0
        public void can_add_and_retrive_basic_class()
        {
            MicroMap.Initialize();
            MicroMap.Register <Interface1, Class1>();

            var instance = MicroMap.GetInstance <Interface1>();

            Assert.AreEqual(instance.GetType(), typeof(Class1));
        }
예제 #2
0
        public void can_build_up_single_depenancy()
        {
            MicroMap.Initialize();
            MicroMap.Register <Interface1, Class1>();
            MicroMap.Register <Interface2, Class2>();

            var instance = MicroMap.GetInstance <Interface2>();

            Assert.AreEqual(instance.GetType(), typeof(Class2));

            Assert.AreEqual(instance.Class1.GetType(), typeof(Class1));
        }
예제 #3
0
        public void can_add_and_retreive_from_func_definition()
        {
            MicroMap.Initialize();
            MicroMap.Register <Interface1>(x =>
            {
                var class1 = new Class1();
                return(class1);
            });

            var instance = MicroMap.GetInstance <Interface1>();

            Assert.AreEqual(instance.GetType(), typeof(Class1));
        }
예제 #4
0
        public void can_add_and_retrieve_static_class()
        {
            var staticClass = new Class1();

            MicroMap.Initialize();
            MicroMap.Register <Interface1>(staticClass);

            var instance  = MicroMap.GetInstance <Interface1>();
            var instance2 = MicroMap.GetInstance <Interface1>();

            Assert.AreEqual(instance, staticClass);
            Assert.AreEqual(instance2, staticClass);
        }
예제 #5
0
        public void builds_up_complex_dependancy()
        {
            MicroMap.Initialize();
            MicroMap.Register <Interface1, Class1>();
            MicroMap.Register <Interface2>(x => new Class2(x.GetInstance <Interface1>()));
            MicroMap.Register <Interface3, Class3>();

            var instance = MicroMap.GetInstance <Interface3>();

            Assert.AreEqual(instance.GetType(), typeof(Class3));

            Assert.AreEqual(instance.Class1.GetType(), typeof(Class1));
            Assert.AreEqual(instance.Class2.GetType(), typeof(Class2));
        }