After looking at several container frameworks, I think we should
add a new lookup mechanism to the Avalon Framework.
I know this issue has been discussed before several times, but why
not doing it again after some years inbetween?

Now with ECM and Fortress a Service (Interface) declares in most cases
a constant ROLE, like this:

public interface MyService {
    String ROLE = MyService.class.getName();
    ...
}

I don't know how this is done with Merlin. 

Anyways, the lookup is then done using this constant:

MyComponent c = (MyComponent)this.serviceManager.lookup( MyService.ROLE );

or

MyComponent c = (MyComponent)this.serviceManager.lookup( MyService.ROLE +
'/' + hint );

There is never a lookup that uses some custom role name, like
lookup("my-parser"); I think such lookups with custom role names
should not be used anyway as they are way too error-prone.

And even worse, ECM has the ugly concept of Selectors, so you first
lookup a selector using MyService.ROLE+"Selector" and then the
component from the selector using the hint. With the following semantics
you combine the two in one interface.

Now, what do you think of using an easier solution:
public interface Locator {
    Object lookup(Class clazz, String hint); // or Object hint
}

With this interface, you don't need the ROLE constant anymore and the
container can check the type of the returned object avoiding class cast
exceptions. And you can see directly in your code which type is returned
by the lookup. (Creating proxies is also a little bit easier as the lookup
method knows which interface to proxy without having the need to get
this information from somewhere else).

This approach is also used by other container frameworks and imho it gives
the lookup method more meaning and reduces errors because of typos.

So, I propose to add a new interface with this lookup semantics to avalon
framework
with a corresponding IoC interface to give this locator to components.
The default implementation for all containers at avalon could be that
a lookup(Class clazz, String hint) is "converted" to a 
serviceManager.lookup(clazz.getName()) if hint is null or
serviceManager.lookup(clazz.getName() + '/' + hint) otherwise.

WDYT?


Carsten 

Carsten Ziegeler 
Open Source Group, S&N AG
http://www.osoco.net/weblogs/rael/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to