public void Approve(Invoice invoice) { decimal discount = _discounters .Aggregate(0m, (previous, discounter) => discounter.Calculate(invoice) + previous); invoice.ApprovedAmount = invoice.Total - discount; _emailSender.Send("Approved " + invoice.ApprovedAmount + " for " + invoice.Customer); }
static void Main(string[] args) { var container = new Container(cfg => { cfg.Scan(scanner => { scanner.AddAllTypesOf<IDiscountApplier>(); scanner.AssemblyContainingType<Program>(); scanner.WithDefaultConventions(); }); cfg.For<IInvoiceApprover>() .DecorateAllWith<LoggingApprover>(); }); var approver = container.GetInstance<IInvoiceApprover>(); var invoice = new Invoice { Total = 2000m, Customer = "Joe", State = "KC" }; approver.Approve(invoice); }
public decimal Calculate(Invoice invoice) { if (invoice.Total > 1000m) { return 50m; } return 0m; }
public void Approve(Invoice invoice) { Console.WriteLine("Starting approval for " + invoice.Customer); _inner.Approve(invoice); Console.WriteLine("Finished approval for " + invoice.Customer); }
public decimal Calculate(Invoice invoice) { if (invoice.State == "KC") { return invoice.Total * 0.1m; } return 0m; }
public decimal Calculate(Invoice invoice) { if (invoice.Customer == "Joe") { return 10m; } return 0m; }