View Full Version : manually add object to the container.
Greetings,
Is there anyway to manually add an object to the Spring container ?
The reason I'm asking is because I'm using ASP.NET 2.0 and I have a customer membership provider. My custom membership provider instance is initialized by ASP.NET 2.0 and I would like Spring manges this instance for me as well.
Any suggestion is appreciated.
Hieu
Rick Evans
10-21-2005, 08:13 PM
Hi Hieu
You can manually add 'singleton' objects into the container; the mantra for doing so is...
WebApplicationContext.Current.ObjectFactory.Regist erSingleton("membershipProvider", membershipProvider);
Please do ping the forums again if you need any clarification about this, because I realise that the answer is terse :)
Have a good weekend, cheers
Rick
wow, that's a quick response and I did not expect you answered that quick :). Thanks a lot...I will give it a try.
hmm I just take a look at my code and I don't see where it would be applicable to call WebApplicationContext . The way I wire all the objects is I declare the object in objects xml file ... and then I call ContextRegistry to load the config file. I don't use Page class from Spring since there are some problems w/ the master page stuff. I don't use the page handler from spring either. Is there nething that I need to change ?
another question:
when I manually register the object to the container by calling RegisterSingleton from ObjectFactory, this will happen b4 or after the container loading the objects.xml file ?
Thanks
Rick Evans
10-21-2005, 09:11 PM
Hi Hieu
Darn, I knew that reply was too short :|
If you aren't using any of the Spring.Web functionality, you can always access the root container like so...
((IConfigurableApplicationContext )ContextRegistry.GetContext()).ObjectFactory.Regis terSingleton("membershipProvider", membershipProvider);
As you can see, it is slightly more involved... support for ASP.NET 2.0 will be included in the forthcoming 1.1 release of Spring.Web (scheduled for the end of the year), so there should (will) be support for integration with the ASP.NET 2.0 Provider model in that timeframe.
Cheers
Rick
Rick Evans
10-21-2005, 09:24 PM
Hi Hieu
When I manually register the object to the container by calling RegisterSingleton from ObjectFactory, this will happen b4 or after the container loading the objects.xml file?
After.
Yes, this is an issue. This means that objects that have a dependency on the object that is being registered as a singleton will not have that dependency injected into them (or will have to use Dependency Lookup to get access to the registered singleton). What you need in this case is a factory (object) that will indirectly supply (in your case) the custom membership provider pulled from the (ASP.NET) configuration. I am investigating this right now (or will be as soon as I finish this post)... as soon as I have something concrete, I will post again, so keep watching this space :D
Ciao
Rick
thanks for your reply Rick.
I'm not sure if I sure put this in a different thread but here it is anyway.. :)
I have a Custom Membership Provider and it's instantiated by ASP.NET framework. Is it possible to inject a dependency into that customer provider ?
Can AOP do it ? or is there an easier way ?
Thanks so much
Rick Evans
10-21-2005, 09:26 PM
Hi Hieu
This sure is a busy thread tonight isn't it? :D
I am looking into this right now... I'll keep you posted.
Ciao
Rick
Hi Rick,
Is there ne updates ? :)
Thanks
Aleksei Kachanov
10-25-2006, 07:43 AM
There are any news about UP feature?
Erich Eichinger
10-25-2006, 08:52 PM
Hi,
Since Provider instantiation is completely out of control for spring, I doubt that it ever will be possible to use DI on custom providers.
But one may use the same technique Spring's PageHandlerFactory is using. I've proposed a solution for a custom SiteMapProvider on another thread (http://forum.springframework.net/showthread.php?t=691)
cheers,
Erich
Mark Pollack
01-03-2008, 05:43 PM
Hi,
Just ran across this old thread, you can now perform DI on custom providers (http://www.springframework.net/docs/1.1/reference/html/web.html#d0e13476). (22.3.3. Injecting dependencies into custom providers)
Cheers,
Mark
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.