Services and Bindings - expected usage scenarios
Remi Forax
forax at univ-mlv.fr
Tue Nov 29 15:03:16 UTC 2016
Hi Vitaliy,
> Is it the intent of project Jigsaw that the service loader becomes a central and
> ubiquitous mechanism in the day to day work of plain old java developers?
You make my day with that sentence :)
More seriously, there are two parts in a dependency injection (DI) mechanism.
The first part, is the user interface, how to get an implementation of a service in a field, a parameter, etc. Most of us use libraries that use annotations like @Inject and are happy with that.
The second part is how a DI mechanism gather the implementations of a service, here each framework is different even if crawling the code of the whole application seems a popular idea.
In a jigsaw world, crawling the whole application make less sense.
It means that:
- the code that crawls the application code has to have some special rights
- after having crawled the whole application, the DI may stop the application because there are no implementation of a service.
So the application can stop at runtime due to a configuration issue.
What the Java Platform Module Spec propose is:
- to define the directives provides/uses in the module-info makes them part of the configuration that can be checked at deployment time.
- to enhance the ServiceLoader to 'publish' an implementation of a service even if the service impl is not visible.
So in my opinion, the ServiceLoader is not something most of the Java devs will interact with directly, but something DI libraries will use internally.
regards,
Rémi
----- Mail original -----
> De: "Vitaliy Pisarev" <vitaliy.pisarev at hpe.com>
> À: jigsaw-dev at openjdk.java.net
> Envoyé: Mardi 29 Novembre 2016 12:35:54
> Objet: Services and Bindings - expected usage scenarios
> Another best practices question.
>
> I am aware that the ServiceLoader API is not new to Java. What's new in Java 9
> is that is has been put forward to the front of the stage and it is now very
> easy
> for a service provider to register a service.
>
> The thing is that up until now, the ServiceLoader was a relatively low level
> component, primarily used by infrastructure components that loaded plugins that
> implemented various java specs.
> It is no surprise than that the ServiceLoader is something that very few ever
> heard of.
>
> Is it the intent of project Jigsaw that the service loader becomes a central and
> ubiquitous mechanism in the day to day work of plain old java developers?
> As far as I am concerned, it is a very useful tool even when I do not have a
> plugin architecture and just want a module to expose a certain service via an
> interface without having to jump throw hooks
> in order to provide the consumer a way to instantiate it..
>
> Which leads me to the next question: is the returned instance a singleton or a
> prototype?
More information about the jigsaw-dev
mailing list