So far in reading about possibilities of injection to custom membership providers, I\'ve found two possible ways to do it:
One is the following: http://bugsquash.blo
I wouldn't go with implicit property injection, since the container will skip over the property if the type is not (correctly) registered, instead of failing fast (more info here). Instead I would use the Service Locator, but write a wrapper membership provider that does not contain any logic, but simply requests a membership provider from the service locator and calls that implementation. Jonas Gauffin wrote such a thing for MVC (using the DependencyResolver
service locator), which is quite nice (also available on NuGet), but it is easy to do yourself.
Although the use of the service locator is considered an anti-pattern, please remember that the membership model must be configured through the web.config and this part of the system does not use the DependencyResolver.Current
itself. Also writing such a DependencyResolverMembershipProvider
is just a bit of mechanics and can be considered part of the composition root, not of the application. Calling the container inside your composition root is not a problem.