Hi I am using the Ninject.MVC Nuget package with my MVC3 app and I have the current bindings setup for some constructor injection.
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IUnitOfWork>().To<ERSUnitOfWork>();
kernel.Bind<IRepository<Recipe>>().To<GenericRepository<Recipe>>();
}
My controller example is below:
public class RecipesController : Controller
{
private readonly IUnitOfWork unitOfWork;
private readonly ERSDbContext context;
private readonly IRepository<Recipe> recipeRepository;
public RecipesController(IUnitOfWork unitOfWork, IRepository<Recipe> recipeRepository)
{
this.context = new ERSDbContext();
this.unitOfWork = unitOfWork;
this.recipeRepository = recipeRepository;
}
}
I want to remove the private DBContext property from the controller and pass the new ERSDbContext() to the constructors of ERSUnitOfWork and the GenericRepository as part of the constructor injection that Ninject is performing, but preferably keep the initialising of the ERSDbContext class inside the controller?
Any help on how you do this would be appreciated. Thanks
I am kind of hoping that it doesn't require my NinjectWebCommon class having to create the DbContext, I wanted that to be initialised in the controller.