static void Main(string[] args) { WindsorContainer container = new WindsorContainer(); container.Register(Component.For<Commerce>()); // first class needs to be registered as well container.Register(Component.For<IBillingProcessor>().ImplementedBy<BillingProcessor>()); container.Register(Component.For<ICustomer>().ImplementedBy<Customer>()); container.Register(Component.For<INotifier>().ImplementedBy<Notifier>()); container.Register(Component.For<ILogger>().ImplementedBy<Logger>()); Console.WriteLine("Castle Windsor 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(); }
public void ProcessOrder(OrderInfo orderInfo) { _BillingProcessor.ProcessPayment(orderInfo.CustomerName, orderInfo.CreditCard, orderInfo.Price); _Logger.Log("Billing processed"); _Customer.UpdateCustomerOrder(orderInfo.CustomerName, orderInfo.Product); _Logger.Log("Customer updated"); _Notifier.SendReceipt(orderInfo); _Logger.Log("Receipt sent"); }
void INotifier.SendReceipt(OrderInfo orderInfo) { // send email to customer with receipt Console.WriteLine(string.Format("Receipt sent to customer '{0}' via email.", orderInfo.CustomerName)); }
public void SendReceipt(OrderInfo orderInfo) { Console.WriteLine("Sending receipt to customer {0} for {1} with amount {2}", orderInfo.CustomerName, orderInfo.Product, orderInfo.Price); }