Ejemplo n.º 1
0
        public void ResolveAndRegisterInstance()
        {
            INDOContainer container = new NDOContainer();
            var           car1      = container.ResolveOrRegisterInstance <ICar>("bmw", _ => new BMW());
            var           car2      = container.ResolveOrRegisterInstance <ICar>("bmw", _ => new BMW());

            Assert.AreSame(car1, car2);

            var car3 = container.ResolveOrRegisterInstance <ICar>("ford", _ => new Ford());

            Assert.AreNotSame(car1, car3);

            var car4 = container.ResolveOrRegisterInstance <ICar>("bmw2", _ => new BMW());

            Assert.AreNotSame(car1, car4);
        }
Ejemplo n.º 2
0
        public void ResolveAndRegisterInstanceWithFactory()
        {
            INDOContainer container = new NDOContainer();

            container.ResolveOrRegisterInstance("bmw", _ => new BMW());
            var bmw = container.Resolve(typeof(BMW), "bmw");

            Assert.IsNotNull(bmw);
            Assert.AreEqual(typeof(BMW), bmw.GetType());
            var bmw2 = container.Resolve(typeof(BMW), "bmw");

            Assert.AreSame(bmw, bmw2);
        }