Re[2]: Cross module single ServiceProvider for JPMS services
Alex Sviridov
ooo_saturn7 at mail.ru
Sun Apr 19 14:56:54 UTC 2020
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.bateman at 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
More information about the jigsaw-dev
mailing list