[Seaside] Re: Application/Session Objects

Yanni Chiu yanni at rogers.com
Wed Feb 22 17:05:00 UTC 2006


Richard Huxton wrote:
> Rich Warren wrote:
>> Where/how should I create objects that will be available to the entire 
>> application or session?
> I'm in a similar position to Rich as chance would have it, so I'll tack 
> my query onto his if that's OK. I'm looking for hooks at start/end of 
> request processing to fetch/return db connections to a pool.

All WAComponent instances (i.e. an instance of your custom subclass)
can always find their corresponding session instance via "self session".
As Philippe has posted, you can create your own subclass of WASession,
to hold your database connection and other objects. I just create a
generic session with one instance variable that holds a dictionary.
That way I don't have to add/remove new slots, during development.
It's somewhat inconvenient to use though (#at: and #at:put: vs. getter/setter).

Instead of using the config app., I prefer to code in the #initialize
method something like:

	(self registerAsApplication: 'foobar')
		preferenceAt: #sessionExpirySeconds put: 8*60*60;
		preferenceAt: #sessionClass put: PUISession;
		yourself.

To close/release your database connection your WASession subclass
should implement an #unregistered method to clean up the connection.
#unregistered gets called some time after the session expiry.

BTW, Richard, aren't you a regular in postgresql. I had to check
what list I was reading. I'm curious what led you to Seaside.
Anyhow, welcome aboard.

-- 
Yanni Chiu



More information about the Seaside mailing list