//Main static void Main(string[] args) { var ioc = new IoC_Container(); ioc.RegisterSingleton <Ice_Cream>(); var fruit = ioc.Resolve <IFruit>(); fruit.FruitType = "Edited Strawberry"; var secondFruit = ioc.Resolve <IFruit>(); //Console.WriteLine("Initial entry");; //ioc.RegisterSingleton<Test>(); //ioc.RegisterTransient<dependency1>(); //var testInstance1 = ioc.Resolve<Test>(); //Console.WriteLine(testInstance1.test); //testInstance1.test = "modified test"; //var testInstance2 = ioc.Resolve<Test>(); //Console.WriteLine(testInstance2.test); }
public void ShouldResolveTransient() { //arrange var ioc = new IoC_Container(); ioc.RegisterTransient <IFruit, Strawberry>(); //act var fruit = ioc.Resolve <IFruit>(); fruit.FruitType = "Edited Strawberry"; var secondFruit = ioc.Resolve <IFruit>(); //assert Assert.Equal("Strawberry", secondFruit.FruitType); }
public void ShouldThrowError() { //arrange var ioc = new IoC_Container(); //act & assert Assert.Throws <ArgumentException>(() => ioc.Resolve <Ice_Cream>()); }
public void ShouldRecursivelyResolveDependencies() { //arrange var ioc = new IoC_Container(); ioc.RegisterSingleton <Ice_Cream>(); ioc.RegisterSingleton <IBase, Cream>(); ioc.RegisterSingleton <Milk>(); ioc.RegisterTransient <IFruit, Banana>(); //act var x = ioc.Resolve <Ice_Cream>(); Assert.Equal("Banana", x.Fruit.FruitType); }