[Seaside] Application context

Pat Maddox pat.maddox at gmail.com
Mon May 18 02:43:09 UTC 2009


On Sun, May 17, 2009 at 6:44 PM, Ramon Leon <ramon.leon at allresnet.com> wrote:
>> "ANComponent userRepository"
>> userRepository
>>        TheUserRepository ifNil: [TheUserRepository := GDRepository for:
>> ANUser].
>>        ^ TheUserRepository
>>
>> "ANComponent>>initialize"
>> initialize
>>        super initialize.
>>        userRepository := ANComponent userRepository.
>>
>
> 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?

There are a few different ways for objects to get a dependency,
looking up a singleton is only one of them.  I'd prefer not to use it.
 Let me show you some fake code that should hopefully demonstrate what
I want to do better than I've explained it so far.

MyBlogApp new userRepository: UserRepository new;
    mountAt: '/us/blog';
    run.

MyBlogApp new userRepository: UserRepository new;
    mountAt: '/ca/blog';
    run.

Each of those is an instance of my blog app, and runs separately from
the other.  The userRepository automatically gets injected into the
components that make up the application.  This way they can just look
up their local instance variable as opposed to grabbing a singleton.

Is that clearer?  That's the gist of what I'm trying to do.  Now I
just need to know how to do it with Seaside.

Pat


More information about the seaside mailing list