The projects in my solution are set up like this:
- App.Data
- App.Models
- App.Web
In App.Data, I'm using Entity Framework to access my data with a bunch of Repositories to abstract interaction with it. For obvious reasons, I would like my App.Web to reference only the App.Data project and not Entity Framework.
I'm using Constructor Injection to give my Controllers a reference to a Repository container that looks like this:
public interface IDataRepository
{
IUserRepository User { get; set; }
IProductRepository Product { get; set; }
// ...
}
public class DataRepository : IDataRepository
{
private readonly AppContext _context;
public DataRepository(AppContext context)
{
_context = context;
}
// ...
}
DataRepository
will have a AppContext
object (which inherits from Entity Framework's DbContext
) that all the child Repositories will use to access the database.
So finally we come to my problem: how do I use Constructor Injection on DataRepository
considering it's a code library and has no entry-point? I can't bootstrap AppContext
in App.Web because then I have to reference Entity Framework from that project.
Or am I just doing something stupid?