Ninject with MembershipProvider | Roleprovider

I use ninject as my IoC, and I wrote the role provider as follows:

public class BasicRoleProvider : RoleProvider { private IAuthenticationService authenticationService; public BasicRoleProvider(IAuthenticationService authenticationService) { if (authenticationService == null) throw new ArgumentNullException("authenticationService"); this.authenticationService = authenticationService; } /* Other methods here */ } 

I read that Provider classes get an instance before ninject gets to inject an instance. How do I get around this? I currently have this ninject code:

 Bind<RoleProvider>().To<BasicRoleProvider>().InRequestScope(); 

From this answer here .

If you mark your dependencies with [Inject] for your properties in your provider class, you can call kernel.Inject(MemberShip.Provider) - this will assign all dependencies to your properties.

I do not understand this.

+7
source share
1 answer

I believe this aspect of the ASP.NET framework is very configuration driven.

For your last comment, what they mean is that instead of relying on the constructor injection (which comes up when the component is created), you can use the setter injection instead, for example:

 public class BasicRoleProvider : RoleProvider { public BasicRoleProvider() { } [Inject] public IMyService { get; set; } } 

It will automatically add an instance of your registered type to the property. Then you can make a call from your application:

 public void Application_Start(object sender, EventArgs e) { var kernel = // create kernel instance. kernel.Inject(Roles.Provider); } 

Suppose that you registered your role provider in the config. Registering a provider this way still provides a lot of modularity, as the implementation and application of your provider are still very decoupled.

+9
source

All Articles