Services and Bindings - expected usage scenarios
mark.reinhold at oracle.com
mark.reinhold at oracle.com
Tue Nov 29 16:10:19 UTC 2016
2016/11/29 6:54:35 -0800, vitaliy.pisarev at hpe.com:
> ...
>
> I am looking at the great features in Java 9 and I know that we are
> going to "jump" on the new module system with all the encapsulation it
> gives us. But I and my fellow Architects are very unsure what to
> think of the ServiceLoader.
>
> Some of the push-back I get is that it is a "low level component"
> meant for authors of infrastructure libraries. Others tell me to
> forget about using the ServiceLoader as a Service Locator and stick to
> good old Spring. Yet others tell me that the Java Expert group has
> actually taken a stand in the "Dependency Injection vs ServiceLocator"
> debate, by streamlining the ServiceLocator pattern instead of going
> with JDK level Dependency Injection.
>
> Discussions are heated, and I figured to go to the source instead of
> deducing our own conclusions with so little information.
I agree largely with what Rémi wrote nearby, though I'd put it a bit
differently.
The Java SE Platform does not, itself, do Dependency Injection, and it
almost certainly never will. Not every application needs DI.
Java SE should, however, provide the primitives needed by all types of
applications, including those that use DI frameworks built on top of it.
SE modules can therefore identify service users and providers, and the
existing SE ServiceLoader API has been enhanced accordingly.
If you're writing an application without a DI framework but have a need
for loose coupling between modules then you should use the ServiceLoader
API directly. If you're using a DI framework then we hope that, over
time, DI frameworks will leverage the ServiceLoader API as appropriate.
That change is, however, not something that those of us who work on the
module system can make ourselves; we can only enable and encourage it.
- Mark
More information about the jigsaw-dev
mailing list