Custom objectbuilder attribute, [CreateShared]

Topics: Web Client Software Factory, UIP Application Block discussion
Feb 14, 2008 at 3:09 PM
Hi, as a solution to the problem of having multiple objects on the same page communicating with each other I've created a custom objectbuilder attribute. I'm asking for input on this, if anyone have an opinion about it. Any input is greatly appreciated.

The attribute makes the objectbuilder use the IHttpContextLocatorService to check if an object of this type has been created. If not it gets the mapped type and creates an instance and stores it in the context. If one has already been created it returns this one.
The attribute also takes a parameter "key" which allowes the creation of multiple independant instances per request.

I can now use this attribute to create a shared instance of the controller in my presenters. By exposing events on the controller that presenters can listen to I have created a way for the presenters to communicate without making them dependant of each other.

This works really well for my project, but I'm wondering if this is a good way to do it. If someone want the code for the attribute I can put it either here or on the contribute site.

Thanks in advance,
Mats
Coordinator
Feb 29, 2008 at 6:17 AM
We had talked about something similar in the WCSF team room (making a class a singleton per user or per session), but were not able to get it into the release.
Your approach sounds pretty good. I would recommend asking to post it on the WCSFContrib site.

Michael Puleio - patterns & practices
Webhttp://msdn.microsoft.com/practices/
Bloghttp://blogs.msdn.com/mpuleio/
Mar 3, 2008 at 6:50 AM
Great, thank you for your input. I'll try to get it up on the contrib site.

/Mats
Mar 16, 2008 at 8:14 AM

MatsL wrote:
Great, thank you for your input. I'll try to get it up on the contrib site.

/Mats


Looking forward to se this up on the contrib site :-)!
Mar 19, 2008 at 9:47 AM
syggen> I had some problems getting a hold of the coordinators of the contrib project but yesterday I got a response.
I will put it up as soon as I can, probably after the weekend. Gonna try to create some illustrative example as well. :-)

I also added the ability to specify the lifetime of the shared object. You can choose between Request, Session and Application.

/Mats
Mar 24, 2008 at 9:02 PM
I added the attribute to the contrib site now. I also added a simple sample that shows how to use it.

I haven't been able to add the lifetime functionality yet. The parameter creation was changed in WCSF 2.0 and now involves quite a lot of IL-code emitting.
After some headscratching and debugging I got the request-lifetime to work, I'll add Session and Application lifetime support later on.

Hope it works well for you!

Mats Lycken
http://mats.softgear.se
http://www.softgear.se
Mar 27, 2008 at 7:30 AM
Nice!

I will look into this ASAP!

/Christoffer aka syggen