예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 public decimal Calculate(Invoice invoice)
 {
     if (invoice.Total > 1000m)
     {
         return 50m;
     }
     return 0m;
 }
예제 #4
0
 public void Approve(Invoice invoice)
 {
     Console.WriteLine("Starting approval for " + invoice.Customer);
     _inner.Approve(invoice);
     Console.WriteLine("Finished approval for " + invoice.Customer);
 }
예제 #5
0
 public decimal Calculate(Invoice invoice)
 {
     if (invoice.State == "KC")
     {
         return invoice.Total * 0.1m;
     }
     return 0m;
 }
예제 #6
0
 public decimal Calculate(Invoice invoice)
 {
     if (invoice.Customer == "Joe")
     {
         return 10m;
     }
     return 0m;
 }