Example #1
0
 public void MyIocContainerShouldReturnTheSameInstanceOfSingletonTypes()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>(LifeCycleTypes.SINGLETON);
     var worker0 = ioc.Resolve(typeof(ISimpleService));
     var worker1 = ioc.Resolve(typeof(ISimpleService));
     Assert.AreEqual(worker0, worker1);
 }
Example #2
0
 public void MyIocContainerShouldReturnNewInstancesOfTransientTypes()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>();
     var worker0 = ioc.Resolve(typeof(ISimpleService));
     var worker1 = ioc.Resolve(typeof(ISimpleService));
     Assert.AreNotEqual(worker0, worker1);
 }
Example #3
0
        public void MyIocContainerShouldReturnTheSameInstanceOfSingletonTypes()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>(LifeCycleTypes.SINGLETON);
            var worker0 = ioc.Resolve(typeof(ISimpleService));
            var worker1 = ioc.Resolve(typeof(ISimpleService));

            Assert.AreEqual(worker0, worker1);
        }
Example #4
0
        public void MyIocContainerShouldReturnNewInstancesOfTransientTypes()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>();
            var worker0 = ioc.Resolve(typeof(ISimpleService));
            var worker1 = ioc.Resolve(typeof(ISimpleService));

            Assert.AreNotEqual(worker0, worker1);
        }
Example #5
0
 public void MyIocContainerShouldResolveADependency()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>();
     var worker = ioc.Resolve(typeof(ISimpleService));
     Assert.AreEqual(typeof(SimpleWorker), worker.GetType());
 }
Example #6
0
        public void MyIocContainerShouldResolveADependency()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>();
            var worker = ioc.Resolve(typeof(ISimpleService));

            Assert.AreEqual(typeof(SimpleWorker), worker.GetType());
        }
Example #7
0
 public void MyIocContainerShouldResolveNestedDependencies()
 {
     MyIocContainer ioc = new MyIocContainer();
     ioc.Register<ISimpleService, SimpleWorker>();
     ioc.Register<IComplexService, ComplexWorker>();
     var complexWorker = ioc.Resolve(typeof(IComplexService));
     Assert.AreEqual(typeof(ComplexWorker), complexWorker.GetType());
     Assert.AreEqual(typeof(SimpleWorker), (complexWorker as ComplexWorker).NestedSimpleService.GetType());
 }
Example #8
0
        public void MyIocContainerShouldResolveNestedDependencies()
        {
            MyIocContainer ioc = new MyIocContainer();

            ioc.Register <ISimpleService, SimpleWorker>();
            ioc.Register <IComplexService, ComplexWorker>();
            var complexWorker = ioc.Resolve(typeof(IComplexService));

            Assert.AreEqual(typeof(ComplexWorker), complexWorker.GetType());
            Assert.AreEqual(typeof(SimpleWorker), (complexWorker as ComplexWorker).NestedSimpleService.GetType());
        }