<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Red IO" <redio.development@gmail.com><br><b>To: </b>"amber-dev" <amber-dev@openjdk.org><br><b>Sent: </b>Monday, February 20, 2023 6:59:43 PM<br><b>Subject: </b>Dependency Injection<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="auto"><div dir="auto">Reason/Background:</div>I was building a server application (in java) designed around the mediator pattern and dependency injection inspired by a c# server application tutorial. So I was researching but every dependency injection framework was relying on bytecode manipulation to do the injection.</div></blockquote><div><br></div><div>Bytecode manipulation at compile-time (like Quarkus) or runtime (like Spring) ?<br data-mce-bogus="1"></div><div>And there are several DI libraries that leverage annotation processors without doing bytecode transformation, i think the most popular is Dagger 2.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="auto"><div dir="auto">For background I really dislike bytecode manipulation for production code. </div><div dir="auto">So I researched what the jdk provides and what not. I discovered that the jdk provides service loading capabilities in form of the ServiceLoader api. But it is pretty barebones only allowing creation of service implementations providing a no-args constructor.</div><div dir="auto"><br></div><div dir="auto">Idea:</div><div dir="auto">I thought that this could be expanded to allow loading of services that depend on other services (In form of constructor parameters) that can be loaded with associated ServiceLoaders. </div><div dir="auto">So I coded a small test wrapper for ServiceLoader that does the injection of known services. </div><div dir="auto">I used MethodHandles to create factory handles that use the associated loaders to fill in the constructor and in that way avoided bytecode manipulation.</div></div></blockquote><div><br></div><div>I do not understand, once a method handle becomes hot, the JDK will generate the corresponding bytecodes, so how it is different from a DI that generate bytecodes ? <br data-mce-bogus="1"></div><div>And usually it's harder to get good performance from method handles if the JIT does not see them as a constant.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="auto"><div dir="auto"><br></div><div dir="auto">Suggestion:</div><div dir="auto">I was wondering if this concept would be interesting to incorporate into the jdk as an expansion of the ServiceLoader api.</div></div></blockquote><div><br></div><div>There was a jlink plugin doing the ServiceLoader resolution at link time if the service was specified in the module-info, i do not know if it still exist or not, but it looks like a good condenser for the project Leyden.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="auto"><div dir="auto"><br></div><div dir="auto">Great regards </div><div dir="auto">RedIODev </div></div></blockquote><div><br></div><div>RĂ©mi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>