ServiceSelectors have fallen out of favor due to giving us
*two* ways to get at a dependency instead of one. Basically,
this is the problem:
Suppose component A has a dependency on an Output service.
Component A needs two of those - Output/std and Output/err,
for standard and error output, respectively. So component
A uses a ServiceSelector:
ServiceSelector selector =
(ServiceSelector) manager.lookup (Output.ROLE);
Output stdOut = (Output) selector.select ("std");
Output stdErr = (Output) selector.select ("err");
In the same container, we want to put component B. (Maybe
we have a component C that is dependent on both A and B.)
B wants an Output service, any one will do. The problem
is that B is coded this way:
Output out = (Output) manager.lookup (Output.ROLE);
But the lookup() call will return a ServiceSelector. Boom.
This is why selectors are bad.
Instead, A should do this:
Output stdOut = (Output) manager.lookup (Output.ROLE + "/std");
Output stdErr = (Output) manager.lookup (Output.ROLE + "/err");
Then B can do this:
Output out = (Output) manager.lookup (Output.ROLE);
and it will all be just fine.
But, what if you have a third component, B2, that also looks up like
this:
Output out = (Output) manager.lookup (Output.ROLE);
And you want B and B2 to use *different* implementations of the role?
And here we get to the good part of the Phoenix/Merlin lookup pattern.
Namely, the role names are scoped to each component. This means I
can do this (pseudo-config):
<component id="output-1" role="Output" class="OutputImplOne"/>
<component id="output-2" role="Output" class="OutputImplTwo"/>
<component id="output-3" role="Output" class="OutputImplThree"/>
<component role="A" class="AImpl">
<dependency role="Output/std" provided-by="output-1"/>
<dependency role="Output/err" provided-by="output-2"/>
</component>
<component role="B" class="BImpl">
<dependency role="Output" provided-by="output-3"/>
</component>
<component role="B2" class="BImpl">
<dependency role="Output" provided-by="output-2"/>
</component>
Basically, it allows you *for each component* to explicitely define
exactly what implementation will be returned for any given lookup
key.
/LS
> From: J Aaron Farr [mailto:[EMAIL PROTECTED]
> >
> > Phoenix doesn't support the Selector. Timothy's approach is the
> > correct
> > one for a Phoenix environment.
> > -pete
> >
>
> :/
>
> Are there plans to support it in the future?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]