Hello Simo,

Ok, I'm in line with your goal, especially if myapp has simply to bindService( AnotherProcessor.class )[.fromClassLoader(ClassLoader)];

I will think come in a few days with hopefully ideas on way to qualify bindings.

I guess in case on absence of qualification, autobinding could be applied (of course, if more than 1 implementation if found, an exception should be thrown).

Thx, Eric

On 13/01/2013 12:14, Simone Tripodi wrote:
Salut Eric!

... but does myapp still needs to say in its module construction the
following?

the answer is NO :)
You just have to create the Injector by specifying which services have
to be automatically discovered:

Injector injector = createInjector( new ServiceLoaderModule()
{

     @Override
     protected void configure()
     {
         bindService( CreditCardProcessor.class 
)[.fromClassLoader(ClassLoader)];
         ...
         bindService( AnotherProcessor.class )[.fromClassLoader(ClassLoader)];
     }

} );

Services implementations are defined in
META-INF/services/org.acme.api.CreditCardProcessor file(s) - this is
something that is already partially working, see
<http://onami.incubator.apache.org/spi/services.html>

What is missing is "just" a way to define how to qualify bindings.

Thanks in advance for more feedbacks!
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/


On Sun, Jan 13, 2013 at 12:56 PM, Eric Charles <[email protected]> wrote:
Hello Simo,
Ok,
- put the jar you want
- myapp defines

@Inject
@Named( "Visa" )
private CreditCardProcessor creditCardProcessor;

... but does myapp still needs to say in its module construction the
following?
bind(CreditCardProcessor.class).annotatedWith(Names.named("Visa")).to(VisaCreditCardProcessor.class);

If the answer is 'no', I understand you point and I will think about it the
next days.

If the answer is 'yes, myapp still needs to explictely do it', it's just
classical injection and we don't need extra layer.

Thx, yes or no? :)
Eric



On 13/01/2013 11:51, Simone Tripodi wrote:

Salut Eric!

On Sun, Jan 13, 2013 at 12:27 PM, Eric Charles <[email protected]> wrote:

However, I miss the problem you are trying to resolve...
Are you looking for a way to put in acme-visa.jar some 'stuff', and reuse
it
in myapp.jar in the annotations, without having to redefine them in the
guide module creation.

For example, acme-visa would define the conditions for which
VisaCreditCardProcessor would be chosen, and you simply have to call (not
definining) those?


Once services are automatically discovered and bound - with qualifiers
- in my application I could require for injections such as, for
example:

class MyApp
{

      @Inject
      @Named( "Visa" )
      private CreditCardProcessor creditCardProcessor;

}

without knowing the CreditCardProcessor implementation details - just
put your jars in the classpath and let's bind services without
explicitly specify them.

Does it help on clarifying it?
TIA, all the best!
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/


Reply via email to