hi alfie,

i don't know if i'm missing something but you could
solve it this way:

public Service buildService(@Inject @Sysmbol("whatever") Long numeric, 
@InjectService("VariantA") Service serviceA, @InjectService("VariantB") 
Service serviceB)
{
    switch(numeric)
   {
        case 2: return serviceA;
        case 42: return serviceB;
        default:
        throw new Exception();
    }
}

if you want to use the Service without qualifier you 
could define another inteface for the variants

g,
kris




"Alfie Kirkpatrick" <alfie.kirkpatr...@ioko.com> 
15.07.2009 10:42
Bitte antworten an
"Tapestry users" <users@tapestry.apache.org>


An
"Massimo Lusetti" <mluse...@gmail.com>, "Tapestry users" 
<users@tapestry.apache.org>
Kopie

Thema
RE: Dynamic service binding based on symbol source







Further to my last mail I think it could be possible to have a module
method convention like:

                 public static com.acme.service.MyService 
bindByConfiguration() {
                 }

This would look for a symbol "com.acme.service.MyService" based on the
return type and use a variant on the ConstructorServiceCreator to
instantiate the service.

Or perhaps a ServiceBinder.bind(MyService.class,
"the.symbol.name.for.impl.class") method would work. It seems a bit
tidier.

Either should be possible since ServiceBuilderMethodInvoker is able to
resolve symbols as parameters via
InternalUtils.calculateParametersForMethod. It's just that the current
code/encapsulation level isn't really geared for what I want to do -- I
need a bit of both ConstructorServiceCreator and
ServiceBuilderMethodInvoker. But I'll keep digging.

Regards, Alfie.

-----Original Message-----
From: Massimo Lusetti [mailto:mluse...@gmail.com] 
Sent: 14 July 2009 13:47
To: Tapestry users
Subject: Re: Dynamic service binding based on symbol source

On Tue, Jul 14, 2009 at 2:43 PM, Alfie
Kirkpatrick<alfie.kirkpatr...@ioko.com> wrote:


> I would like to instantiate a different service implementation
depending
> on property file configuration, eg. a stub for testing and a real
> service for deployments. I'd like to put the FQN in my property file
> which is then wrapped in a SymbolProvider.

I highly suggest you to build a chain of command or a strategy pattern
depending on service type and let the IoC do the work for you.

-- 
Massimo
http://meridio.blogspot.com


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


Reply via email to