Ejemplo n.º 1
0
        public void SimpleRegistration()
        {
            INDOContainer container = new NDOContainer();

            container.RegisterType <ICar, BMW>();
            container.RegisterType <Driver>();

            //Resolves dependencies and returns the Driver object
            Driver drv = container.Resolve <Driver>();

            Assert.AreEqual("Running BMW - 1 mile", drv.RunCar());
        }
Ejemplo n.º 2
0
        public void DoubleRegisterTypeWithName()
        {
            INDOContainer container = new NDOContainer();

            container.RegisterType <ICar, BMW>(new ContainerControlledLifetimeManager());
            container.RegisterType <ICar, Audi>(new ContainerControlledLifetimeManager());

            var car1 = container.Resolve <ICar>("bmw");
            var car2 = container.Resolve <ICar>("bmw");
            var car3 = container.Resolve <ICar>("audi");

            Assert.AreSame(car1, car2);
            Assert.AreNotSame(car1, car3);
        }
Ejemplo n.º 3
0
        public void DoubleRegisterTypeWithNameTransient()
        {
            INDOContainer container = new NDOContainer();

            container.RegisterType <ICar, BMW>();
            container.RegisterType <ICar, Audi>();

            var car1 = container.Resolve <ICar>("bmw");
            var car2 = container.Resolve <ICar>("bmw");
            var car3 = container.Resolve <ICar>("audi");

            Assert.AreNotSame(car1, car2);
            Assert.AreNotSame(car1, car3);
        }
Ejemplo n.º 4
0
        public void OverwriteInstanceRegWithTypeReg()
        {
            var container = new NDOContainer();

            container.RegisterInstance <ICar>(new Ford());
            container.RegisterType <ICar, BMW>();
            Assert.IsTrue(container.Resolve <ICar>() is BMW);
        }
Ejemplo n.º 5
0
        public void SimpleRegistrationWithOneType()
        {
            INDOContainer container = new NDOContainer();

            container.RegisterType <BMW>();

            var car = container.Resolve <BMW>();

            Assert.AreEqual(typeof(BMW), car.GetType());
        }
Ejemplo n.º 6
0
        public void DoubleResolve()
        {
            INDOContainer container = new NDOContainer();

            container.RegisterType <ICar, BMW>(new ContainerControlledLifetimeManager());

            var car1 = container.Resolve <ICar>();
            var car2 = container.Resolve <ICar>();

            Assert.AreSame(car1, car2);
        }
Ejemplo n.º 7
0
        public void RegistrationWithAnonymousOverride()
        {
            INDOContainer container = new NDOContainer();

            container.RegisterType <Driver>();

            //Resolves dependencies and returns the Driver object
            Driver drv = container.Resolve <Driver>(null, new ParameterOverride(new BMW()));

            Assert.AreEqual("Running BMW - 1 mile", drv.RunCar());
        }
Ejemplo n.º 8
0
        public void RegisterWithContainerLifetime()
        {
            var container = new NDOContainer();

            container.RegisterType <ICar, BMW>(new ContainerControlledLifetimeManager());

            var driver1 = container.Resolve <Driver>();

            Assert.AreEqual("Running BMW - 1 mile", driver1.RunCar());

            var driver2 = container.Resolve <Driver>();

            Assert.AreEqual("Running BMW - 2 mile", driver2.RunCar());
        }
Ejemplo n.º 9
0
        public void ResolveWithParameterInParentContainer()
        {
            var container1 = new NDOContainer();

            container1.RegisterType <Driver>();
            var container2 = container1.CreateChildContainer();

            container2.RegisterInstance <ICar>(new BMW());
            var drv = container2.Resolve <Driver>();

            Assert.NotNull(drv);
            Assert.AreEqual("Running BMW - 1 mile", drv.RunCar());

            container1 = new NDOContainer();
            container1.RegisterInstance <ICar>(new BMW());
            container2 = container1.CreateChildContainer();
            container2.RegisterType <Driver>();
            drv = container2.Resolve <Driver>();
            Assert.NotNull(drv);
            Assert.AreEqual("Running BMW - 1 mile", drv.RunCar());
        }
Ejemplo n.º 10
0
        public void ResolveWithChildContainer2()
        {
            INDOContainer container1 = new NDOContainer();

            container1.RegisterType <ICar, BMW>(new ContainerControlledLifetimeManager());

            var car1 = container1.Resolve <ICar>();


            var container2 = container1.CreateChildContainer();
            var car2       = container2.Resolve <ICar>();

            Assert.AreSame(car1, car2);

            container2.RegisterType <ICar, BMW>(/* Transient */);
            car2 = container2.Resolve <ICar>();

            Assert.AreNotSame(car1, car2);

            container2.Dispose();

            car2 = container1.Resolve <ICar>();
            Assert.AreSame(car1, car2);
        }