0

Possible Duplicate:
Inject repository to custom membership provider with Ninject

I have searched much about this topic too much the most close answer was here MVC 3 ninject custom membership context disposed error but I don't have any idea about the details all I have in my application is a domain contains my entities and abstraction for repositories and the implementation everything works fine when I use my Ninject binding like this

 public class NinjectControllerFactory : DefaultControllerFactory{
    readonly IKernel _kernel;


    public NinjectControllerFactory(){
        _kernel=new StandardKernel();
        AddBindings();
    }


    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType){
        return controllerType == null
            ? null
            : (IController) _kernel.Get(controllerType);
    }
 void AddBindings(){
        _kernel.Bind<IٍSomeRepository>()
            .To<EFSomeRepository>();

but I have no idea how to bind the customer membership provider I have read about this that I have to inject via a poperty but I don't know how, any ideas ?

Community
  • 1
  • 1

1 Answers1

0

First, you should be using Ninject.MVC3 rather than your own controller factory. Ninject.MVC3 takes care of hooking everything up, you just need to provide your mappings in App_Start\NinjectWebCommon.cs

Second, don't bother with using Ninject for Membership, unless you're using a custom membership provider. Even then, it's a lot less of a pain if you don't mix Ninject and Membership. I would suggest not bothering with it unless you really know what you're doing.

The problem is that Membership is a static class, that creates a static instance of the Membership Provider. This means it doesn't get destroyed at the end of the request. There are ways around this, but in general, it's just a lot easier to use Membership as-is than try to make it work with DI.

The question you linked to solves a specific problem, relating to injecting business logic into your custom membership provider. If you need to do this, then it might be a good choice. However, I find that most custom membership providers tend to be very simple.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291