I am really having a hard time trying to figure out where the EF Context is managed in an MVC app.
I am using the Service/Repository/EF approach and was playing with the UnitOfWork pattern with a context inside of it, and then using it inside the controller actions to utilize various services. It works, but by doing this, I am making the controllers dependent on EF right?
Any suggestions?
If you rely upon abstractions and create an IUnitOfWork and IRepository encapsulating the EF Context the Controller would be dependent on the abstractions and not any concrete implementation.
The repository and unit of work themselves are the only classes that would be dependent on Entity Framework or whatever ORM you are using.
Edit as per request:
A simple Unit Of Work implementation could be:
You would of course make sure that your services/repositories use the same context as the Unit of Work by injecting the same context into them.