Lets say I am in shopping cart scenario which involves following steps:
- Get Cart from database
- Calculate tax
- Total everything
Project.Core(Has all domain classes)
public CartItem
{
public int Id { get; set; }
public string Desc { get; set; }
}
public CartDetails
{
public int Id { get; set; }
public List<CartItem> CartItems { get; set; }
public Decimal Tax { get; set; }
public Decimal Total { get; set; }
}
Project.DAL
public class CartDAL
{
public List<CartItem> GetCart(int cartId)
{
//execute sql here, get datareader or datatable
//loop thru the rows and mait into a List<CartItem>
return List<CartItem>
}
}
Look into Dapper or Massive, instead of manually like above.
http://code.google.com/p/dapper-dot-net/
https://github.com/robconery/massive
Project.BLL
public class CartBLL
{
CartDAL cartDAL = new CartDAL();
public CartDetails GetCartDetails(int cartId)
{
var cartDetails = new CartDetails();
cartDetails.CartItems = cartDAL.GetCart(cartId);
cartDetails.Tax = cartDAL.GetCart(cartId);
cartDetails.Total = cartDAL.GetCart(cartId);
return cartDetails;
}
}
Project.Web
public class CartController
{
CartBLL cartBLL = new CartBLL();
public ActionResult Index(int Id)
{
var cartDetails = cartBLL.GetCartDetails(Id);
// Make a cartViewModel
View(cartViewModel);
}
}
Project.WPF
//Nothing much changes in desktop comapared to Web, just call the BLL stuff and you are set
CartBLL cartBLL = new CartBLL();
var cartDetails = cartBLL.GetCartDetails(Id);
//Populate view
So, basically you have to reuse your BLL in all the front end projects