I’d like to use EF directly in a business / service layer without using repositories but wondered where the best place to create / dispose the context if I want to make the class testable using a test DB?
Should it be using DI in the service constructor and mark the class as IDisposable and get rid of it there or just wrap each call in a using block?
I’m not sure on your reluctance on a repository class, but this is where I’ve been creating a destroying the EF context for my service layer.
So for my MVC web app, I register the repository using Autofac with lifetimescope
My account service will get a reference to a repository instance from the container and will have access to a single context throughout the life time of the web request. Once the request is finished, Autofac will call dispose on the repository and clean up the context.