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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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())); }
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)}"); }
public SingleInstanceResolver(BridgeIoc container, Type targetType) { _container = container; _targetType = targetType; }
public TransientResolver(BridgeIoc container, Type targetType) { _container = container; _targetType = targetType; }