コード例 #1
0
ファイル: Program.cs プロジェクト: consolelogreece/Concepts
        //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);
        }
コード例 #2
0
        public void ShouldThrowError()
        {
            //arrange
            var ioc = new IoC_Container();

            //act & assert
            Assert.Throws <ArgumentException>(() => ioc.Resolve <Ice_Cream>());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }