I have an MVC3 app using Autofac and a custom membership provider.
If I try and inject the provider using the ctor, I get an error: 'No parameterless constructor defined for this object.'
public class MyMemberShipProvider : MembershipProvider
{
IUserRepository userRepository;
public MyMemberShipProvider(IUserRepository userRepository)
{
this.userRepository = userRepository;
}
You can not inject into the in-built providers (Membership / Roles). You can use the MVC 3 DependencyResolver with Autofac.
A quick example...
public override bool ValidateUser(string username, string password)
{
var userRepo = DependencyResolver.Current.GetService<IUserRepository>();
return userRepo.ValidateUser(username, password);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With