Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            IINGExchangeRate iNGExchangeRate2020 = new INGExchangeRate2020();
            IINGExchangeRate iNGExchangeRate2021 = new INGExchangeRate2021();

            IBTExchangeRate bTExchangeRate2020 = new BTExchangeRate2020();
            IBTExchangeRate bTExchangeRate2021 = new BTExchangeRate2021();

            IABExchangeRate aBExchangeRate2020 = new ABExchangeRate2020();
            IABExchangeRate aBExchangeRate2021 = new ABExchangeRate2021();

            IBCRExchangeRate bCRExchangeRate2020 = new BCRExchangeRate2020();
            IBCRExchangeRate bCRExchangeRate2021 = new BCRExchangeRate2021();

            Dictionary <Type, object> dependecyInjectionContainer = new Dictionary <Type, object>();

            dependecyInjectionContainer.Add(typeof(IINGExchangeRate), iNGExchangeRate2020);
            dependecyInjectionContainer.Add(typeof(IBTExchangeRate), bTExchangeRate2020);
            dependecyInjectionContainer.Add(typeof(IABExchangeRate), aBExchangeRate2020);
            dependecyInjectionContainer.Add(typeof(IBCRExchangeRate), bCRExchangeRate2020);

            ConstructorInfo constructorInfo = typeof(ING).GetConstructors().FirstOrDefault();

            List <object> ingParams = new List <object>();

            foreach (ParameterInfo parameterInfo in constructorInfo.GetParameters())
            {
                Console.WriteLine(parameterInfo.ParameterType.ToString());

                ingParams.Add(dependecyInjectionContainer[parameterInfo.ParameterType]);
            }

            //var parameters = new object[1];
            //parameters[0] = ingParams[0];

            //ING ingInstance = Activator.CreateInstance(typeof(ING), parameters) as ING;

            //ING ingInstance = Activator.CreateInstance(typeof(ING), new object[] { ingParams.ToArray() }) as ING;

            var ingCtorParams = ingParams.ToArray();

            ING ingInstance = Activator.CreateInstance(typeof(ING), ingCtorParams) as ING;
            //ING ingInstance = Activator.CreateInstance(typeof(ING), ingParams) as ING;

            //IBank ing = new ING(dependecyInjectionContainer[typeof(IINGExchangeRate)] as IINGExchangeRate);
            IBank ing = Activator.CreateInstance(typeof(ING), ingCtorParams) as ING;
            IBank bt  = new BT(dependecyInjectionContainer[typeof(IBTExchangeRate)] as IBTExchangeRate);
            IBank ab  = new AB(dependecyInjectionContainer[typeof(IABExchangeRate)] as IABExchangeRate);
            IBank bcr = new BCR(dependecyInjectionContainer[typeof(IBCRExchangeRate)] as IBCRExchangeRate);

            Console.WriteLine($"ING converts 100 EUR into {ing.ExchangeInRON(100)}");
            Console.WriteLine($"BT converts 100 EUR into {bt.ExchangeInRON(100)}");
            Console.WriteLine($"AB converts 100 EUR into {ab.ExchangeInRON(100)}");
            Console.WriteLine($"BCR converts 100 EUR into {bcr.ExchangeInRON(100)}");


            Console.ReadKey();
        }
Example #2
0
 static void Main(string[] args)
 {
     Console.WriteLine("Hello World!");
     IBank ing = new ING();
     IBank bt = new BT();
     Console.WriteLine($"ING converts 100 EUR into {ING.");
     Console.ReadKey();