I've gone through quite a few articles on the repository pattern and had some questions. I'm trying to implement this in a ASP.NET 4.0 application. The architecture is a layered architecture with a Presentation Layer, Business Layer and Data Layer. From this article, http://www.primaryobjects.com/CMS/Article108.aspx
I have created the MYSQLRepository
(DataLayer)
public class MySQLRepository:IOrderRepository
{
public List<Order> GetOrders()
{
List<Order> orders = new List<Order>();
orders.Add(new Order(1,"A"));
orders.Add(new Order(2,"B"));
return orders;
}
}
My Business Layer looks like this
public class OrderBL
{
IOrderRepository orderrep;
public OrderBL(IOrderRepository repository)
{
orderrep = repository;
}
public List<Order> GetOrders()
{
return orderrep.GetOrders();
}
}
Now my question is that in the presentation layer, I'm expected to do this
protected void Page_Load(object sender, EventArgs e)
{
OrderBL orderBL = new OrderBL(new MySQLRepository());
List<Order> orders = orderBL.GetOrders();
foreach (Order order in orders)
{
Response.Write(order.OrderId.ToString() + ". " + order.OrderNo + "<br>");
}
}
In order to do this, I have to reference my DataLayer in the presentation layer. Isn't that wrong? Ideally I would only want to reference my Business Layer. IS something wrong in my implementation or is it not the right place to implement the pattern. I have seen many examples using ASP.NET MVC and it seems to work well there.
Also, Do i really need dependency injection here?
Thanks for the help Soni