Hi Alan
Yes, you read that correctly. Do you mean that in ServiceProvider that is in
moduleA we
will do something like this:
if (!SerivceProvider.class.getModule().canUse(S)) {
SerivceProvider.class.getModule().addUses(S)
}
//here we some logic and return S service.
Best regards
>Воскресенье, 19 апреля 2020, 17:22 +03:00 от Alan Bateman
><alan.bate...@oracle.com>:
>
>On 19/04/2020 15:00, Alex Sviridov wrote:
>> 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? If I read this correctly then we
>> have code in module A looking to load
>service provider of type S but A's module declaration doesn't declares
>`uses S`. Have you tried the Module addUses method? That will add the
>"use" edge at run-time that should make this work.
>
>-Alan.
--
Alex Sviridov