Thanks Howard. Yes, that's quite a bit of boilerplate but looks like
the only other option, especially if you want both A and B separately
known as services.

Kalle


On Tue, Feb 28, 2012 at 12:03 PM, Howard Lewis Ship <hls...@gmail.com> wrote:
> I've thought about these "chimeric" services before.
>
> Let's say you want to seperate services, A and B.  You have an
> implementation class IM that implements both A and B.
>
> Define a new interface, C:
>
> public interface C {  A getA(); B getB(); }
>
> public class CImpl implements C {
>  public final IM im;
>
>  public CImpl(IM im) { this.im = im; }
>
>  public A getA() { return im; }
>
>  public B getB() { return im; }
> }
>
> Let's assume IM is a class, not an interface, and so should be
> instantiated directly.  In a module class:
>
> public static C buildC(@Autobuild IM im) {
>  return new CImpl(im);
> }
>
> public static A buildA(C c) { return c.getA(); }
>
> public static B buildB(C c) { return c.getB(); }
>
>
> This gets the job done, but it's tedious.
>
>
>
>
> On Tue, Feb 28, 2012 at 11:52 AM, Kalle Korhonen
> <kalle.o.korho...@gmail.com> wrote:
>> I have an interesting case where I'm trying to fit third-party code to
>> work under Tapestry IoC. A service is made available by binding to the
>> "main" interface of a class, but I know the implementation supports
>> another interface. Is there a way to make it known with the other
>> interface as well for the IoC container? Never needed something like
>> this before, but I was a bit surprised I didn't find a clean way to
>> support it. I could imagine something like
>> ServiceBindingOptions.knownAs(Class... aliases) although perhaps that
>> would open a different can of worms. I'm trying to avoid creating
>> another interface so I wouldn't have to change the service type, but I
>> suppose that's my best bet. Anybody run into a similar case and have
>> other creative solutions for the problem?
>>
>> Kalle
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@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-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>

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

Reply via email to