When using entity framework, is it bad practice to inject the repository into a controller?
For example if I have a service:
public class DogService
{
IMyDbContext _myDbContext;
public DogService(IMyDbContext myDbContext)
{
_myDbContext = myDbContext;
}
public void CreateDog(string name)
{
//create a dog using the myDbContext
}
}
Would the above be bad practice since we are not explicitly disposing of the repository, and would it be better to do:
public void CreateDog(string name, IMyDbContext myDbContext)
{
using(myDbContext)
{
//create a dog using the myDbContext
}
}
the stucture of mydbcontext:
public class MyDbContext : DbContext, IMyDbContext {}
How do I dispose of the myDbContext?