[Seaside] Application context

Ramon Leon ramon.leon at allresnet.com
Mon May 18 01:58:19 UTC 2009

> I agree with James but I'll be more specific, how about this...
> UserRepository class>>forApp: anApp
>     ^ (Repository ifNil: [Repository := Dictionary new ])
>         at: anApp ifAbsentPut: [ GDRepository for: ANUser ]
> ANComponent>>initialize
>     super initialize.
>     userRepository := UserRespository forApp: self session baseUrl
> printString.
> No need to stick the repository on a component class, create a unique class
> just for it, you get an automatic singleton because classes *are* singletons
> and why shouldn't a user repository be its own abstraction?
> Ramon Leon
> http://onsmalltalk.com

Or even better...

ANUser class>>repositoryForApp: anAppName
    ^ (Repository ifNil: [Repository := Dictionary new ])
        at: anAppName ifAbsentPut: [ GDRepository for: self ]

    super initialize.
    userRepository := ANUser repositoryForApp: self session baseUrl

Let the ANUser class itself hold the repository for all its instances for
all entry points.  Then you don't have to think as much, you just establish
the pattern that a repository for any class is on that class.  This works
for prototyping in Squeak/Pharo and in Gemstone works as an actual
production solution because it'll automatically be persisted.

Ramon Leon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20090517/cbf7b787/attachment-0001.htm

More information about the seaside mailing list