I have C# solution with 5 projects in it
- Data Layer (class library with EF)
- Business Layer (class library)
- Presentation Layer (ASP.NET MVC)
- Common library
- MSTest project
I have my references setup like so;
- MVC references business layer
- Business layer references Data Layer
- All project references the common library
I've always have this obsession (OCD) of not having the presentation to have to reference EF and/or the Data Layer project because it should not know what my data layer is doing or how it's doing it's job. In my opinion it should just know which functions to call from the service layer and expect a return value. Maybe it is right and maybe it is wrong.
On my service layer I have a class called Services that has constructor injection like the code below so it can easily be tested using a mocking framework;
public class Services : IServices
{
public Services(IDbContext dbContext, IBuilders builders)
{
_dbContext = dbContext;
_builders = builders;
}
}
So now - If I need to use this on my MVC project I'll have to have use DI to handle this situation so I don't have to tightly couple my controllers with my DbContext class. But this requires me having to reference my Data Layer from my Presentation Layer, is that an acceptable practice? What's a good way to handle this type of situation?