static void Main(string[] args) { Container container = new Container(); // requires full .NET 4 targetted framework container.Configure(reg => reg.For<IBillingProcessor>().Use<BillingProcessor>()); container.Configure(reg => reg.For<ICustomer>().Use<Customer>()); container.Configure(reg => reg.For<INotifier>().Use<Notifier>()); container.Configure(reg => reg.For<ILogger>().Use<Logger>()); Console.WriteLine("StructureMap 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.GetInstance<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)); }