public void the_tax_calculator_can_be_injected_in_a_marked_constructor() { using (IKernel kernel = new StandardKernel()) { kernel.Bind<ITaxCalculator>().To<TaxCalculator>().WithConstructorArgument("rate", .2M); var lineItem1 = new SaleLineItem("Gone with the wind", 10M, 1); var lineItem2 = new SaleLineItem("Casablanca", 5M, 2); var sale = kernel.Get<Sale3>(); // note that we do not mention tax calculator at all here! sale.AddItem(lineItem1); sale.AddItem(lineItem2); Assert.Equal(24M, sale.GetTotal()); } }
public void AddItem(SaleLineItem item) { lineItems.Add(item); }
public void the_tax_calculator_can_be_resolved() { using (IKernel kernel = new StandardKernel()) { kernel.Bind<ITaxCalculator>().To<TaxCalculator>().WithConstructorArgument("rate", .2M); var lineItem1 = new SaleLineItem("Gone with the wind", 10M, 1); var lineItem2 = new SaleLineItem("Casablanca", 5M, 2); var sale = new Sale(kernel.Get<ITaxCalculator>()); sale.AddItem(lineItem1); sale.AddItem(lineItem2); Assert.Equal(24M, sale.GetTotal()); } }