Hey Simone
here's a nice article about that:
http://blog.mycila.com/2009/10/jdk-serviceloader-as-google-guice.html
or: https://code.google.com/p/mycila/wiki/MycilaGuice#Service_Loader

Chris

Am 13.01.2013 10:55, schrieb Simone Tripodi:
> Salut Eric,
>
> thanks a lot for your thoughts, much more than appreciated! This
> helped me understanding that adding some extra metadata in
> META-INF/services files is not the right direction to address that
> problem :)
>
> Let's recap: what I wanted to add to guice, in the SPI module, is the
> ability to binding services implementation by discovering them via the
> "ServiceLoader".
> So, let's suppose we have the following service:
>
> package org.acme.api;
> public interface CreditCardProcessor {
>     void doSomething();
> }
>
> contained in acme-api.jar
>
> then, we do have a PayPal implementation:
>
> package org.acme.paypal;
> public class PayPalCreditCardProcessor
>     implements CreditCardProcessor
> {
>     public void doSomething()
>     {...}
> }
>
> defined in acme-paypal.jar, and then a MasterCard implementation:
>
> package org.acme.mastercard;
> public class MasterCardCreditCardProcessor
>     implements CreditCardProcessor
> {
>     public void doSomething()
>     {...}
> }
>
> defined in acme-mastercard.jar.
>
> Now, the idea is binding all these implementation automagically,
> without scanning the classpath (which is something covered by
> onami-autobind), but using the ServiceLoader approach. So, let's
> immagine acme-paypal.jar content as:
>
> acme-paypal.jar
> -------------------------------------------------------------------------------
> org/acme/paypal/PayPalCreditCardProcessor.class
> META-INF/services/org.acme.api.CreditCardProcessor
>
> where org.acme.api.CreditCardProcessor contains
>
> META-INF/services/org.acme.api.CreditCardProcessor
> -------------------------------------------------------------------------------
> org.acme.paypal.PayPalCreditCardProcessor
>
> it is now easy to immagine the same scenario for the acme-mastercard.jar file.
>
> Let's suppose that our classpath is in the form of
>
> acme-api.jar:acme-paypal.jar:acme-mastercard.jar
>
> what I would like to obtain, for next version od SPI, is
>
> bind(CreditCardProcessor.class)
>         .annotatedWith(?!?!??!)
>         .to(PayPalCreditCardProcessor.class);
> bind(CreditCardProcessor.class)
>         .annotatedWith(?!?!??!)
>         .to(MasterCardCreditCardProcessor.class);
>
> The missing part are, as you can notice, the binding annotations,
> because I am looking for a way to specify qualifiers...
>
> Component configuration is out of scope for that extension.
>
> Do you have any suggestion on how to discover binding annotations as well?
>
> TIA, have a nice weekend!
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/

Reply via email to