First I decided to create one Interface called it IDataAccessLayer
and started putting everything into it: methods like GetUsers()
, GetUser(int id)
, GetOrderByNumber(int number)
, DeleteOrder(int Id)
etc.
That worked just perfect at first. But then I realized that the concrete implementation of DataLayer:IDataLayer
is growing to big. I decided to cut it into several partial class files. Still I was feeling that I'm doing something really wrong.
Then I decided to create interfaces for each logical part like IUsers
, IOrders
, IItems
etc. Didn't work, because I was accessing repository through one dependent property injected into controller's constructor. So I couldn't just add another property everytime I need to use different type of dataContext in my controller.
Then after many hours reading through articles about Entity Framework, I finally realized that I have to use Repository and Unit of work patterns. And still I need to somehow separate POCOs from my ViewModel objects, although almost all the time they'd be sharing similarities. Automapper helps a lot. But now, I'm not sure how to use everything together. Entity Framework, Patterns, Automapper and Dependency injection framework like Ninject.
I don't have clear understanding how to mix that all into one awesome architecture. Can you please show me some nice examples.