I'm not sure if I did a good job of searching the topics but I can't seem to find answers to my questions. Based from my understanding, Onion Architecture has the UI and Infrastructure on the same layer. Let say I have my UI in ASP.NET MVC project and I have DAL project which is my Infrastructure. Lets assume my code is like the one below:
Core:
//IOrderSaver interface was also defined on the core
public class OrderService
{
private IOrderSaver orderSaver;
public OrderService(IOrderSaver orderSaver)
{
this.orderSaver = orderSaver;
}
public void AcceptOrder(Order order)
{
orderSaver.SaveOrder(order);
}
}
Infrastructure (DAL):
public class OrderSaverDAL : IOrderSaver
{
//implementation goes here
}
Now, in my UI (ASP.NET MVC) I would like to instantiate OrderService class so that it can accept orders. For the UI to do that, it has to pass IOrderSaver to the constructor. It needs to pass OrderSaverDAL.
Questions:
Does the UI (ASP.NET MVC) needs to reference OrderSaverDAL? From my understanding of Onion Architecture (if I understand it correctly), the UI should have no reference to the DAL. Can someone please explain?
If I don't need to reference OrderSaverDAL from my ASP.NET MVC project, how will I construct OrderService within ASP.NET MVC? Can you please guide me by giving sample code on how to achieve this?
Many thanks in advance for the help!