Esempio n. 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();
        }
        static void Main(string[] args)
        {
            Dictionary <Type, object> dependecyInjectionContainer = new Dictionary <Type, object>();

            dependecyInjectionContainer.Add(typeof(IINGExchangeRate), new INGExchangeRate2020());
            dependecyInjectionContainer.Add(typeof(IBTExchangeRate), new BTExchangeRate2020());
            dependecyInjectionContainer.Add(typeof(IRFSExchangeRate), new RFSExchangeRate2020());
            dependecyInjectionContainer.Add(typeof(IBPOSExchangeRate), new BPOSExchangeRate2020());

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

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

            foreach (ParameterInfo parameterInfo in constructorInfo.GetParameters())
            {
                ingParams.Add(dependecyInjectionContainer[parameterInfo.ParameterType]);
            }

            var ingCtorParams = ingParams.ToArray();

            IBank ing  = Activator.CreateInstance(typeof(ING), ingCtorParams) as ING;
            IBank bt   = new BT(dependecyInjectionContainer[typeof(IBTExchangeRate)] as IBTExchangeRate);
            IBank rfs  = new RFS(dependecyInjectionContainer[typeof(IRFSExchangeRate)] as IRFSExchangeRate);
            IBank bpos = new BPOS(dependecyInjectionContainer[typeof(IBPOSExchangeRate)] as IBPOSExchangeRate);


            Console.WriteLine($"ING converts 100 EUR into {ing.ExchangeInRON(100)}");
            Console.WriteLine($"BT converts 100 EUR into {bt.ExchangeInRON(100)}");
            Console.WriteLine($"RFS converts 100 EUR into {rfs.ExchangeInRON(100)}");
            Console.WriteLine($"BPOS converts 100 EUR into {bpos.ExchangeInRON(100)}");

            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Dictionary <Type, object> dependecyInjectionContainer = new Dictionary <Type, object>();

            dependecyInjectionContainer.Add(typeof(IINGExchangeRate), new INGExchangeRate2020());
            dependecyInjectionContainer.Add(typeof(IBTExchangeRate), new BTExchangeRate2020());

            IBank ing = CreateInstance(typeof(ING), dependecyInjectionContainer) as ING;
            IBank bt  = CreateInstance(typeof(BT), dependecyInjectionContainer) as BT;

            Console.WriteLine($"ING converts 100 EUR into {ing.ExchangeInRON(100)}");
            Console.WriteLine($"BT converts 100 EUR into {bt.ExchangeInRON(100)}");
        }
Esempio n. 4
0
 public decimal ExchangeInRON(decimal valueInEUR)
 {
     return(bank.ExchangeInRON(valueInEUR));
 }