I've seen several iterations of this problem in the users list, but the
solution still eludes me.

This is the very basic issue of having two different concrete realizations
of a particular interface and wanting to have a service for each concrete
implementation in a Tapestry 1.5.0.5 environment.

The binding looks like this:

        binder.bind(CommonInterface.class, Concrete1.class).withId("one");
        binder.bind(CommonInterface.class, Concrete2.class).withId("two");

And in various components, something like
@InjectService("one")
private CommonInterface concrete1;

or
@InjectService("two")
private CommonInterface concrete2;

But now I get errors like:
Service interface  CommonInterface is matched by 2 services: one, two.
Automatic dependency resolution requires that exactly one service implement
the interface.

OK, poking around I found things about ContributeAlias, and this example:
public static void contributeAlias(
@InjectService("one") Concrete1 concrete1
Configuration<AliasContribution> configuration)
{
configuration.add(AliasContribution.create(CommonInterface.class,
concrete1));
}

and similarly for Concrete2. But now I get errors like:
Caused by: java.lang.RuntimeException: Exception constructing service
'Alias': Error invoking service builder method
org.apache.tapestry5.services.TapestryModule.buildAlias(Logger, String,
AliasManager, Collection) (at TapestryModule.java:325)....
                            Service 'one' implements interface
CommonInterface, which is not compatible with the requested type
'concrete1'.
at
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78)
at
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)


I've severely clipped out extra stuff from the output, I'll be glad to
provide more details but I suspect this is fairly trivial to fix if you know
the magic, unfortunately I'm an apprentice...

I don't understand when adding ContributeAlias is necessary, it seems to me
that just the "withId" should be sufficient but what do I know?

Thanks
Erick

Reply via email to