Property injection in custom membership provider using Castle

后端 未结 1 1759
予麋鹿
予麋鹿 2020-12-21 12:19

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

相关标签:
1条回答
  • 2020-12-21 12:37

    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.

    0 讨论(0)
提交回复
热议问题