[Seaside] Application context
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 ]
> super initialize.
> userRepository := UserRespository forApp: self session baseUrl
> 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
Or even better...
ANUser class>>repositoryForApp: anAppName
^ (Repository ifNil: [Repository := Dictionary new ])
at: anAppName ifAbsentPut: [ GDRepository for: self ]
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the seaside