I have a Visual Studio solution that has the following:
- MyProject.Domain - POCOs.
- MyProject.Data - ORM (Entity Framework DbContext).
- MyProject.Services - Wrapper around the DbContext. Contains classes that perform business logic.
- MyProject.Web - MVC app that uses the service layer.
For my MVC app, I am using Ninject to inject services into my MVC controllers. The binding in my MVC project looks like this:
kernel.Bind<ISomeService>().To<SomeService>();
This part is working fine. However, I would further like to inject an IDbContext
into my services, and the examples I see online are a little confusing. The examples I see online look make the above code look like this:
kernel.Bind<ISomeService>().To<SomeService>();
kernel.Bind<ISomeDbContext>().To<SomeDbContext>();
Now, since SomeDbContext
is located in MyProject.Data, this means that I have to add a reference to the ORM project in my MVC project. This works, but this seems to defeat the purpose of IoC. The MVC project shouldn't "know" about the ORM, right? Why isn't this considered poor design? What is the proper way to manage this dependency?