Slowly putting an MVC app together with class libraries: MVC > Services > IRepository > EFRepository. Now at the moment, my EFRepository implementations each create a new dbContext in their constructor but this prevents testing so I need to inject the dbContext instead.
I am successfully using unity.mvc3 for DI throughout the rest of my app but am confused as to how to correctly implement the dbContext injection.
- Does a dbContext act as a Unit of Work?
- Is it correct to inject a dbContext into a Repository?
- Am I right in thinking that a dbContext needs to be instantiated per request?
Think I’m just a bit lost on where to go from here. I was thinking that I should have a Unit of Work but it seems to me this would happen at the service layer.
All help appreciated,
James
1 Answer