Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var container = new Container(cfg =>
            {
                cfg.Scan(scanner =>
                {
                    scanner.AddAllTypesOf<IDiscounter>();

                    scanner.AssemblyContainingType<Program>();
                    scanner.WithDefaultConventions();
                });

                cfg.For<IInvoiceApprover>().DecorateAllWith<LoggingInvoiceApprover>();
                cfg.ForSingletonOf<EmailSender>().Use<EmailSender>();
            });

            var approver = container.GetInstance<IInvoiceApprover>();
            var invoice = new Invoice
            {
                Total = 2000m,
                Customer = "Joe",
                State = "KS"
            };

            approver.Approve(invoice);
        }
Ejemplo n.º 2
0
 public decimal Apply(Invoice invoice)
 {
     if (invoice.Customer == "Joe")
     {
         return 10m;
     }
     return 0m;
 }
Ejemplo n.º 3
0
 public decimal Apply(Invoice invoice)
 {
     if (invoice.State == "KS")
     {
         return invoice.Total * 0.1m;
     }
     return 0m;
 }
Ejemplo n.º 4
0
        public void Approve(Invoice invoice)
        {
            Console.WriteLine("Starting approval for " + invoice.Customer);

            _inner.Approve(invoice);

            Console.WriteLine("Finished approval for " + invoice.Customer);
        }
Ejemplo n.º 5
0
 public decimal Apply(Invoice invoice)
 {
     if (invoice.Total > 1000m)
     {
         return 50m;
     }
     return 0m;
 }
Ejemplo n.º 6
0
        public void Approve(Invoice invoice)
        {
            decimal discount = _discounters
                .Aggregate(0m, (current, discounter) 
                    => current + discounter.Apply(invoice));

            invoice.ApprovedAmount = invoice.Total - discount;

            _emailSender.Send("Approved " + invoice.ApprovedAmount + " for " + invoice.Customer);
        }