mirror of
https://github.com/rudollee/LearningMVC.git
synced 2026-08-11 16:32:55 +00:00
Ch. 6
EssentialTools Ninject
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace EssentialTools.Models
|
||||
{
|
||||
public interface IValueCalculator
|
||||
{
|
||||
decimal ValueProducts(IEnumerable<Product> products);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace EssentialTools.Models
|
||||
{
|
||||
public class LinqValueCalculator : IValueCalculator
|
||||
{
|
||||
public decimal ValueProducts(IEnumerable<Product> products)
|
||||
{
|
||||
return products.Sum(p => p.Price);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace EssentialTools.Models
|
||||
{
|
||||
public class Product
|
||||
{
|
||||
public int ProductID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public string Category { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace EssentialTools.Models
|
||||
{
|
||||
public class ShoppingCart
|
||||
{
|
||||
private IValueCalculator calc;
|
||||
|
||||
public ShoppingCart(IValueCalculator calcParam)
|
||||
{
|
||||
calc = calcParam;
|
||||
}
|
||||
|
||||
public IEnumerable<Product> Products { get; set; }
|
||||
|
||||
public decimal CalculatorProdutTotal()
|
||||
{
|
||||
return calc.ValueProducts(Products);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user