Answer the question
In order to leave comments, you need to log in
How to solve problem with Ninject in asp.net mvc?
Hello everyone... I'm using dependency injection in a project...
Here's my class:
class NinjectControllerFactory : DefaultControllerFactory
{
private IKernel ninjectKernel;
public NinjectControllerFactory()
{
ninjectKernel = new StandardKernel();
AddBindigs();
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
return controllerType == null ? null : (IController)ninjectKernel.Get(controllerType);
}
private void AddBindigs()
{
ninjectKernel.Bind<IUserRepository>().To<EFUserReposiroty>();
ninjectKernel.Bind<IProfileRepository>().To<EFProfileRepository>();
ninjectKernel.Bind<IQuestionRepository>().To<EFQuestionRepository>();
ninjectKernel.Bind<ICategoryRepository>().To<EFCategoriesRepository>();
ninjectKernel.Bind<IAnswerRepository>().To<EFAnswerRepository>();
ninjectKernel.Bind<WebContext>().ToSelf().WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings[0].ConnectionString);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question