> There is at least one statement in that code that I don't think is
> true in my experience. The author of that JSR says that "Service
> locators decouple even further but reduce compile time type safety". I
> am not sure what service locators they have been using, but
> java.util.ServiceLoader is definitely typesafe, especially if you use
> it with a Factory interface instead of using reflection to instantiate
> the object manually. In my experience using java.util.ServiceLoader on
> my own projects and in my work with OWLAPI, I have found that you can
> have a typesafe plugin system quite easily without relying on a
> dependency injection system to do it for you.
>

they are not indeed the same kind of service locators, and the one you
are referring is definitely NOT typesafe because in
META-INF/services/com.acme.Interface definition you are free to
specify a class which doesn't implement com.acme.Interface - and you
can find that misconfiguration at *runtime* only.

Modern DI framework allows specify typesafe services in a pure java
config which is checked at *compile* time.

FYI, ServiceLoader is already in use in Any23 to load plugins and
META-INF/services files are generated at compile time via the metainf
library developed by Kohsuke (the Jenkin's guy). Anyway, we've had a
broken test anyway, due to misconfigurations in META-INF/services :)

> However I don't mind if you want to put in JSR-330 annotations in the
> apprpriate places. I am just wary of cases when a library forces you
> to use dynamic dependency injection and either makes it very hard or
> impossible to do it using a plain-old-java way. As long as the code
> doesn't lock things down by doing things like creating private fields
> with no accessors or mutators except for DI magic, I am fine with it.
> Personally, I don't mind maintaining Factories as I am going to be
> using them myself, since I don't generally use DI, and using Open
> Source code I am free to create the factories if they don't exist.
>

I never mentioned adopting a specific framework that forces us on
writing stuff according to its rule, just referenced to the JRS.

Factories are still fine, but not how they are used in the current
codebase - they often get me feel lost while reviewing before the
release.

> Cheers,
>
> Peter

best,
-Simo

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

Reply via email to