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.blogspot.com/2010/11/windsor-managed-membershipproviders.html
Here the author basically suggests to register your custom provider and then have a rather questionable windsor adapter for membership (I don't really like the way in which it instances your provider using a container it gets from HttpApplication
, which it ultimately wraps with the windsor adapter).
This is another, similar option: http://code.google.com/p/webdotnet/source/browse/trunk/Steeg.Framework/Web/Security/MemberShipProvider.cs?r=2
Where you just override Initialize()
and manually instance the dependencies there. At least in the first one, you don't need to instance dependencies by hand (other than the provider itself).
There are then a few which also suggest using a service locator of some kind (MVC's or otherwise)
Then I've come across ninject injecting dependencies to properties on Membership.Provider
rather easily with something like _kernel.Inject(Membership.Provider)
. This is much closer to what I want, keeping the composition root concept which drew me to using DI in the first place.
How can I achieve a similar result using castle?
Update: apparently this has issues with lifecycle management.
Inject repository to custom membership provider with Ninject
Should I go for option #1 then? At least with that I instance the provider myself. So lifecycle management shouldn't be an issue.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…