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

            container.RegisterFunc(() => new 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);
        }
        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);
        }
Пример #4
0
        public void NonGenericClass()
        {
            var container = new BridgeIoc();

            container.RegisterSingleInstance(typeof(TheTest));

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

            Assert.AreEqual(first, second);
            Assert.AreEqual(first.Id, second.Id);
        }
Пример #5
0
        public void InstanceResolve()
        {
            var container = new BridgeIoc();

            container.RegisterSingleInstance <TheTest>(new TheTest());

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

            Assert.AreEqual(first, second);
            Assert.AreEqual(first.Id, second.Id);
        }
Пример #6
0
        public void FuncResolve()
        {
            var container = new BridgeIoc();

            container.RegisterFunc(() => new TheTest());

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

            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(first.Id, second.Id);
        }
Пример #7
0
        public void GenericInterface()
        {
            var container = new BridgeIoc();

            container.RegisterSingleInstance <ITest, TheTest>();

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

            Assert.AreEqual(first, second);
            Assert.AreEqual(first.Id, second.Id);
        }
Пример #8
0
        public void NonGenericInterface()
        {
            var container = new BridgeIoc();

            container.Register(typeof(ITest), typeof(TheTest));

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

            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(first.Id, second.Id);
        }
Пример #9
0
        public void GenericClass()
        {
            var container = new BridgeIoc();

            container.Register <TheTest>();

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

            Assert.AreNotEqual(first, second);
            Assert.AreNotEqual(first.Id, second.Id);
        }
Пример #10
0
        public void InstanceResolve()
        {
            var container = new BridgeIoc();

            container.RegisterInstance(new TheTest());

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

            first.ShouldBeEquals(second);
            first.Id.ShouldBeEquals(second.Id);
        }
Пример #11
0
        public void GenericClass()
        {
            var container = new BridgeIoc();

            container.RegisterSingleInstance <TheTest>();

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

            first.ShouldBeEquals(second);
            first.Id.ShouldBeEquals(second.Id);
        }
Пример #12
0
        public void NonGenericInterface()
        {
            var container = new BridgeIoc();

            container.RegisterSingleInstance(typeof(ITest), typeof(TheTest));

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

            first.ShouldBeEquals(second);
            first.Id.ShouldBeEquals(second.Id);
        }
Пример #13
0
        public static object ConstructObject(BridgeIoc container, Type type)
        {
            var constructor           = type.GetConstructors().Single();
            var constructorParameters = constructor.GetParameters();
            var parameters            = new object[constructorParameters.Length];

            for (var i = 0; i < constructorParameters.Length; i++)
            {
                parameters[i] = container.Resolve(constructorParameters[i].ParameterType);
            }

            return(constructor.Invoke(parameters.ToArray()));
        }
Пример #14
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)}");
        }