public void NonGenericClass()
        {
            var container = new BridgeIoc();

            container.Register(typeof(TheTest));

            var first  = container.Resolve <TheTest>();
            var second = container.Resolve <TheTest>();

            first.ShouldBeNotEquals(second);
            first.Id.ShouldBeNotEquals(second.Id);
        }
        public void GenericInterface()
        {
            var container = new BridgeIoc();

            container.Register <ITest, TheTest>();

            var first  = container.Resolve <ITest>();
            var second = container.Resolve <ITest>();

            first.ShouldBeNotEquals(second);
            first.Id.ShouldBeNotEquals(second.Id);
        }
Ejemplo n.º 3
0
        public void GenericInterface()
        {
            var container = new BridgeIoc();

            container.Register <ITest, TheTest>();

            var first  = container.Resolve <ITest>();
            var second = container.Resolve <ITest>();

            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(first.Id, second.Id);
        }
Ejemplo n.º 4
0
        public void NonGenericClass()
        {
            var container = new BridgeIoc();

            container.Register(typeof(TheTest));

            var first  = container.Resolve <TheTest>();
            var second = container.Resolve <TheTest>();

            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(first.Id, second.Id);
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            // simple all transient registration
            var firstContainer = new BridgeIoc();

            firstContainer.Register <ISum, Adder>();
            firstContainer.Register <ISubtract, Subtractor>();
            firstContainer.Register <ICalc, Calculator>();

            var secondContainer = new BridgeIoc();

            secondContainer.RegisterFunc <ISum>(() => new Adder());         // can register func
            secondContainer.RegisterInstance <ISubtract>(new Subtractor()); // instance
            secondContainer.RegisterSingleInstance <ICalc, Calculator>();   // or single instance (singleton)

            // transient resolving
            var calc1 = firstContainer.Resolve <ICalc>();
            var calc2 = firstContainer.Resolve <ICalc>();

            Console.WriteLine($"Calc1 Id: {calc1.Id}");
            Console.WriteLine($"Calc2 Id: {calc2.Id}");

            Console.WriteLine($"Same id? : {calc2.Id == calc1.Id}");


            // single instance resolving
            var calc3 = secondContainer.Resolve <ICalc>();
            var calc4 = secondContainer.Resolve <ICalc>();

            Console.WriteLine($"Calc1 Id: {calc3.Id}");
            Console.WriteLine($"Calc2 Id: {calc4.Id}");

            Console.WriteLine($"Same id? : {calc3.Id == calc4.Id}");

            Console.WriteLine($"3+4={calc1.Add(3,4)}");
            Console.WriteLine($"7-2={calc1.Subtract(7,2)}");
        }