Hi,

The problem you see is that ServiceLoader.load() is caller-sensitive, so it has 
to be called from the exact module that will use the service.

You can still have some utility method that works on an already instantiated 
service loader:

1. The utility class/method just takes a ServiceLoader instance to consume and 
do you common stuff. 2. The instance is created inside the module that uses it 
and passes to the common utility class.

Uwe

Am April 19, 2020 2:00:01 PM UTC schrieb Alex Sviridov <ooo_satu...@mail.ru>:
>
>Hi all,
> 
>Let's suppose we have modules (A, B, C..) and every module consumes and
>provides services.
>To find these services I want to create one util class, for example
>ServiceProvider that will be used
>by all modules to get necessary services. There are two ideas:
>*  to have one point to control providing services within system
>*  to avoid code duplication.
>However, I can't do it. The problem is that if we put ServiceProvider,
>for example, in module A,
>then it can find only services that module A uses (service is declared
>in  uses in module A module-info).
>Is it possible to do, if yes, then how?
> 
> 
>--
>Alex Sviridov

Reply via email to