You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Erick Erickson <er...@gmail.com> on 2010/05/24 19:58:30 UTC

Problems with @InjectService

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

Re: Problems with @InjectService

Posted by Christophe Cordenier <ch...@gmail.com>.
Hi

Have you tried with
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/annotations/Id.html

@Inject
@Id("one")
private CommonInterface concrete1;

Have you any duplicate build method for the same service with same id ?

2010/5/24 Erick Erickson <er...@gmail.com>

> Well, I've been staring at what comes back as a web page with stack traces
> and it hasn't been
> all that helpful. The class that things get traced back to absolutely does
> an @InjectService("one").
> And I've restarted Eclipse, recompiled the associated project, and verified
> that I wasn't picking up
> a stale class (at least I think I have been, but I've been fooled before).
>
> Or is there a different "console log" that you're referring to?
>
> Erick
>
> On Mon, May 24, 2010 at 4:42 PM, Howard Lewis Ship <hl...@gmail.com>
> wrote:
>
> > Let Tapestry do the work for you; as it instantiates services and
> > other objects, it logs what it's doing; it should be able to point you
> > right at the class (and even line number) of the errant injection.
> > Read the console log.
> >
> > On Mon, May 24, 2010 at 1:19 PM, Erick Erickson <erickerickson@gmail.com
> >
> > wrote:
> > > Howard:
> > >
> > > Thanks for your answer, but I sure don't see where we're injecting by
> > > the type, but that may just mean I need to look harder. Maybe somewhere
> > > we're providing a builder or something.
> > >
> > > But just for clarification, you're saying that I should NOT need to do
> > the
> > > ContributeAlias bit to resolve the bind().withId("one") if all the
> > Tapestry
> > > injections
> > > of the service are annotated wtih @InjectService("one")?
> > >
> > > I guess my next step is to see just how much stuff I can remove before
> > > things
> > > "just work". If I get it back to what looks like a test program I'll
> let
> > you
> > > know.
> > >
> > > Thanks
> > > Erick
> > >
> > >
> > >
> > > On Mon, May 24, 2010 at 3:06 PM, Howard Lewis Ship <hl...@gmail.com>
> > wrote:
> > >
> > >> You should only be getting this error:
> > >>
> > >> Service interface  CommonInterface is matched by 2 services: one, two.
> > >> Automatic dependency resolution requires that exactly one service
> > implement
> > >> the interface.
> > >>
> > >>
> > >> if you are injecting somewhere by type (CommonInterface) rather than
> > >> service id.  The console log will tell you exactly how Tapestry got to
> > >> that point.
> > >>
> > >> On Mon, May 24, 2010 at 11:32 AM, Shing Hing Man <ma...@yahoo.com>
> > wrote:
> > >> > I think you need the Marker annotations.
> > >> > Please check it out at the link below.
> > >> >
> > >> > http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html
> > >> >
> > >> >
> > >> >
> > >> > Shing
> > >> >
> > >> > --- On Tue, 25/5/10, Erick Erickson <er...@gmail.com>
> wrote:
> > >> >
> > >> >> From: Erick Erickson <er...@gmail.com>
> > >> >> Subject: Problems with @InjectService
> > >> >> To: "Tapestry users" <us...@tapestry.apache.org>
> > >> >> Date: Tuesday, 25 May, 2010, 1:58
> > >> >> 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
> > >> >>
> > >> >
> > >> >
> > >> >
> > >> >
> > >> >
> ---------------------------------------------------------------------
> > >> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > >> > For additional commands, e-mail: users-help@tapestry.apache.org
> > >> >
> > >> >
> > >>
> > >>
> > >>
> > >> --
> > >> Howard M. Lewis Ship
> > >>
> > >> Creator of Apache Tapestry
> > >>
> > >> The source for Tapestry training, mentoring and support. Contact me to
> > >> learn how I can get you up and productive in Tapestry fast!
> > >>
> > >> (971) 678-5210
> > >> http://howardlewisship.com
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > >> For additional commands, e-mail: users-help@tapestry.apache.org
> > >>
> > >>
> > >
> >
> >
> >
> > --
> > Howard M. Lewis Ship
> >
> > Creator of Apache Tapestry
> >
> > The source for Tapestry training, mentoring and support. Contact me to
> > learn how I can get you up and productive in Tapestry fast!
> >
> > (971) 678-5210
> > http://howardlewisship.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>



-- 
Regards,
Christophe Cordenier.

Developer of wooki @wookicentral.com

Re: Problems with @InjectService

Posted by Erick Erickson <er...@gmail.com>.
Well, I've been staring at what comes back as a web page with stack traces
and it hasn't been
all that helpful. The class that things get traced back to absolutely does
an @InjectService("one").
And I've restarted Eclipse, recompiled the associated project, and verified
that I wasn't picking up
a stale class (at least I think I have been, but I've been fooled before).

Or is there a different "console log" that you're referring to?

Erick

On Mon, May 24, 2010 at 4:42 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> Let Tapestry do the work for you; as it instantiates services and
> other objects, it logs what it's doing; it should be able to point you
> right at the class (and even line number) of the errant injection.
> Read the console log.
>
> On Mon, May 24, 2010 at 1:19 PM, Erick Erickson <er...@gmail.com>
> wrote:
> > Howard:
> >
> > Thanks for your answer, but I sure don't see where we're injecting by
> > the type, but that may just mean I need to look harder. Maybe somewhere
> > we're providing a builder or something.
> >
> > But just for clarification, you're saying that I should NOT need to do
> the
> > ContributeAlias bit to resolve the bind().withId("one") if all the
> Tapestry
> > injections
> > of the service are annotated wtih @InjectService("one")?
> >
> > I guess my next step is to see just how much stuff I can remove before
> > things
> > "just work". If I get it back to what looks like a test program I'll let
> you
> > know.
> >
> > Thanks
> > Erick
> >
> >
> >
> > On Mon, May 24, 2010 at 3:06 PM, Howard Lewis Ship <hl...@gmail.com>
> wrote:
> >
> >> You should only be getting this error:
> >>
> >> Service interface  CommonInterface is matched by 2 services: one, two.
> >> Automatic dependency resolution requires that exactly one service
> implement
> >> the interface.
> >>
> >>
> >> if you are injecting somewhere by type (CommonInterface) rather than
> >> service id.  The console log will tell you exactly how Tapestry got to
> >> that point.
> >>
> >> On Mon, May 24, 2010 at 11:32 AM, Shing Hing Man <ma...@yahoo.com>
> wrote:
> >> > I think you need the Marker annotations.
> >> > Please check it out at the link below.
> >> >
> >> > http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html
> >> >
> >> >
> >> >
> >> > Shing
> >> >
> >> > --- On Tue, 25/5/10, Erick Erickson <er...@gmail.com> wrote:
> >> >
> >> >> From: Erick Erickson <er...@gmail.com>
> >> >> Subject: Problems with @InjectService
> >> >> To: "Tapestry users" <us...@tapestry.apache.org>
> >> >> Date: Tuesday, 25 May, 2010, 1:58
> >> >> 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
> >> >>
> >> >
> >> >
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> > For additional commands, e-mail: users-help@tapestry.apache.org
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> Howard M. Lewis Ship
> >>
> >> Creator of Apache Tapestry
> >>
> >> The source for Tapestry training, mentoring and support. Contact me to
> >> learn how I can get you up and productive in Tapestry fast!
> >>
> >> (971) 678-5210
> >> http://howardlewisship.com
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Problems with @InjectService

Posted by Howard Lewis Ship <hl...@gmail.com>.
Let Tapestry do the work for you; as it instantiates services and
other objects, it logs what it's doing; it should be able to point you
right at the class (and even line number) of the errant injection.
Read the console log.

On Mon, May 24, 2010 at 1:19 PM, Erick Erickson <er...@gmail.com> wrote:
> Howard:
>
> Thanks for your answer, but I sure don't see where we're injecting by
> the type, but that may just mean I need to look harder. Maybe somewhere
> we're providing a builder or something.
>
> But just for clarification, you're saying that I should NOT need to do the
> ContributeAlias bit to resolve the bind().withId("one") if all the Tapestry
> injections
> of the service are annotated wtih @InjectService("one")?
>
> I guess my next step is to see just how much stuff I can remove before
> things
> "just work". If I get it back to what looks like a test program I'll let you
> know.
>
> Thanks
> Erick
>
>
>
> On Mon, May 24, 2010 at 3:06 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
>
>> You should only be getting this error:
>>
>> Service interface  CommonInterface is matched by 2 services: one, two.
>> Automatic dependency resolution requires that exactly one service implement
>> the interface.
>>
>>
>> if you are injecting somewhere by type (CommonInterface) rather than
>> service id.  The console log will tell you exactly how Tapestry got to
>> that point.
>>
>> On Mon, May 24, 2010 at 11:32 AM, Shing Hing Man <ma...@yahoo.com> wrote:
>> > I think you need the Marker annotations.
>> > Please check it out at the link below.
>> >
>> > http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html
>> >
>> >
>> >
>> > Shing
>> >
>> > --- On Tue, 25/5/10, Erick Erickson <er...@gmail.com> wrote:
>> >
>> >> From: Erick Erickson <er...@gmail.com>
>> >> Subject: Problems with @InjectService
>> >> To: "Tapestry users" <us...@tapestry.apache.org>
>> >> Date: Tuesday, 25 May, 2010, 1:58
>> >> 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
>> >>
>> >
>> >
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> > For additional commands, e-mail: users-help@tapestry.apache.org
>> >
>> >
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems with @InjectService

Posted by Erick Erickson <er...@gmail.com>.
Howard:

Thanks for your answer, but I sure don't see where we're injecting by
the type, but that may just mean I need to look harder. Maybe somewhere
we're providing a builder or something.

But just for clarification, you're saying that I should NOT need to do the
ContributeAlias bit to resolve the bind().withId("one") if all the Tapestry
injections
of the service are annotated wtih @InjectService("one")?

I guess my next step is to see just how much stuff I can remove before
things
"just work". If I get it back to what looks like a test program I'll let you
know.

Thanks
Erick



On Mon, May 24, 2010 at 3:06 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> You should only be getting this error:
>
> Service interface  CommonInterface is matched by 2 services: one, two.
> Automatic dependency resolution requires that exactly one service implement
> the interface.
>
>
> if you are injecting somewhere by type (CommonInterface) rather than
> service id.  The console log will tell you exactly how Tapestry got to
> that point.
>
> On Mon, May 24, 2010 at 11:32 AM, Shing Hing Man <ma...@yahoo.com> wrote:
> > I think you need the Marker annotations.
> > Please check it out at the link below.
> >
> > http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html
> >
> >
> >
> > Shing
> >
> > --- On Tue, 25/5/10, Erick Erickson <er...@gmail.com> wrote:
> >
> >> From: Erick Erickson <er...@gmail.com>
> >> Subject: Problems with @InjectService
> >> To: "Tapestry users" <us...@tapestry.apache.org>
> >> Date: Tuesday, 25 May, 2010, 1:58
> >> 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
> >>
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Problems with @InjectService

Posted by Howard Lewis Ship <hl...@gmail.com>.
You should only be getting this error:

Service interface  CommonInterface is matched by 2 services: one, two.
Automatic dependency resolution requires that exactly one service implement
the interface.


if you are injecting somewhere by type (CommonInterface) rather than
service id.  The console log will tell you exactly how Tapestry got to
that point.

On Mon, May 24, 2010 at 11:32 AM, Shing Hing Man <ma...@yahoo.com> wrote:
> I think you need the Marker annotations.
> Please check it out at the link below.
>
> http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html
>
>
>
> Shing
>
> --- On Tue, 25/5/10, Erick Erickson <er...@gmail.com> wrote:
>
>> From: Erick Erickson <er...@gmail.com>
>> Subject: Problems with @InjectService
>> To: "Tapestry users" <us...@tapestry.apache.org>
>> Date: Tuesday, 25 May, 2010, 1:58
>> 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
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems with @InjectService

Posted by Shing Hing Man <ma...@yahoo.com>.
I think you need the Marker annotations.
Please check it out at the link below.

http://tapestry.apache.org/tapestry5.1/tapestry-ioc/service.html



Shing

--- On Tue, 25/5/10, Erick Erickson <er...@gmail.com> wrote:

> From: Erick Erickson <er...@gmail.com>
> Subject: Problems with @InjectService
> To: "Tapestry users" <us...@tapestry.apache.org>
> Date: Tuesday, 25 May, 2010, 1:58
> 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
> 


      

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org