示例#1
0
        static void Main(string[] args)
        {
            Container = new UnityContainer();

            Container.RegisterType <IBillingProcessor, BillingProcessor>();
            Container.RegisterType <ICustomer, Customer>();
            Container.RegisterType <INotifier, Notifier>();
            Container.RegisterType <ILogger, Logger>();

            Console.WriteLine("Unity DI Container Example");
            Console.WriteLine();

            OrderInfo orderInfo = new OrderInfo()
            {
                CustomerName = "Shreesha",
                Email        = "*****@*****.**",
                Product      = "Laptop",
                Price        = 1200,
                CreditCard   = "1234567890"
            };

            Commerce commerce = Container.Resolve <Commerce>();

            commerce.ProcessOrder(orderInfo);

            Console.WriteLine();
            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Unity DI Container");
            Console.WriteLine("");

            //Not Found this Application of Container();
            //Container _container = new Container();

            _container = new UnityContainer();

            ////Classes  A, B AND C
            //IUnityContainer objContainer = new UnityContainer();
            //objContainer.RegisterType<User>();
            //objContainer.RegisterType<Idal, MySQLDal>();
            //objContainer.RegisterType<Idal, SQLDal>();

            //User userObj = objContainer.Resolve<User>();

            //User userInject1 = new User(new MySQLDal());
            //userInject1.AddByInject();
            //User userInject2 = new User(new SQLDal());
            //userInject2.AddByInject();

            _container.RegisterType <IBillingProcessor, BillingProcessor>();
            _container.RegisterType <ICustomer, Customer>();
            _container.RegisterType <INotifier, Notifier>();
            _container.RegisterType <ILogger, Logger>();

            OrderInfo orderInfo = new OrderInfo()
            {
                CustomerName = "Claudia Almeida",
                Email        = "*****@*****.**",
                Product      = "LCD Monitor Smart Samsung",
                Price        = 259.00f,
                CreditCard   = "1234.5678.9876.5432"
            };

            Console.WriteLine("Production");
            Console.WriteLine("");

            _container.RegisterType <Commerce>();
            //Stoped to "Newing Up classes"
            Commerce commerce = _container.Resolve <Commerce>();

            commerce.ProcessOrder(orderInfo);

            Console.WriteLine("");
            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            Container = new UnityContainer();

            Container.RegisterType <IBillingProcessor, BillingProcessor>();
            Container.RegisterType <ICustomer, Customer>();
            Container.RegisterType <INotifier, Notifier>();
            Container.RegisterType <ILogger, Logger>();

            #region factory
            Container.RegisterType <IBillingProcessorFactory, UnityBillingProcessorFactory>();
            #endregion

            Console.WriteLine("Unity DI Container Example");
            Console.WriteLine();

            OrderInfo orderInfo = new OrderInfo()
            {
                CustomerName = "Miguel Castro",
                Email        = "*****@*****.**",
                Product      = "Laptop",
                Price        = 1200,
                CreditCard   = "1234567890"
            };

            Console.WriteLine("Production:");
            Console.WriteLine();

            Commerce commerce = Container.Resolve <Commerce>();

            commerce.ProcessOrder(orderInfo);

            Console.WriteLine();
            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }