A
A
Alex2014-11-19 19:56:38
ASP.NET
Alex, 2014-11-19 19:56:38

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);
        }
    }

When creating an authorization, I override the MembershipProvider class and have to call the IUserRepository interface there to work with methods by User ... how can I pass my overridden provider to ninject so that the provider recognizes the implementation of this interface ?!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question