I am trying to self bind MembershipProvider in ASP.NET MVC 2 and then use this binding in an AccountController constructor.
This is a snippet from my global.asax.cs
// selfbind MembershipProvider in request scope
Bind<MembershipProvider>().ToSelf().InRequestScope();
And a snippet from service class:
public AccountMembershipService(MembershipProvider provider, IAccountRepository accountRepository)
{
_provider = provider ?? Membership.Provider;
_accountRepository = accountRepository;
}
My problem is that injection isn't working (the injection for AccountRepository does work however). This is the error from Ninject:
Error activating MembershipProvider using self-binding of MembershipProvider
No constructor was available to create an instance of the implementation type.
Activation path:
3. Injection of dependency MembershipProvider into parameter provider of constructor of type AccountMembershipService
2. Injection of dependency IMembershipService into parameter membershipService of constructor of type AccountController
1. Request for IController
Suggestions:
1) Ensure that the implementation type has a public constructor.
2) If you have implemented the Singleton pattern, use a binding with InSingletonScope() instead.
Setting InSingletonScope() makes no difference and I cannot do anything about the constructor since this is not a custom MembershipProvider but the default one that comes with ASP.NET.
I'm stuck here, don't know how to solve this.