<html><head><style id="css_styles" type="text/css"><!--blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc }
blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; }
a img { border: 0px; }
li[style='text-align: center;'], li[style='text-align: center; '], li[style='text-align: right;'], li[style='text-align: right; '] { list-style-position: inside;}
body { font-family: 'Segoe UI'; font-size: 12pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; padding-left: 0.3em; }
--></style></head><body><div><br /></div><div>Hi,</div><div><br /></div><div>I wrote my own DI framework, and byte code manipulation is not a requirement to do DI. The basic functionality is provided with reflection only. Most frameworks should be doing exactly that.</div><div><br /></div><div>Byte code manipulation is only a requirement when the same can't be achieved by using a JDK interface based proxy. If there is no suitable interface that can be proxied in such a way, then the only option left is to create a dynamic subclass. This is often done for i<span>njecting scoped dependencies in a dependency with a different scope (ie, a request scoped dependency injected into a singleton requires the request scoped dependency to be proxied). Other features that may require byte code manipulation are assisted injection, wrappers, AOP, etc.</span></div><div><br /></div><div>--John</div>
<div><br /></div>
<div>------ Original Message ------</div>
<div>From "Red IO" <<a href="mailto:redio.development@gmail.com">redio.development@gmail.com</a>></div>
<div>To "amber-dev" <<a href="mailto:amber-dev@openjdk.org">amber-dev@openjdk.org</a>></div>
<div>Date 20/02/2023 18:59:43</div>
<div>Subject Dependency Injection</div><div><br /></div>
<div id="xf002748e09ec470"><blockquote cite="CABKyW1smmGsbY1mXt5RxVgXNe+yo_juTu9nQh0ZsuXoXBu+UeQ@mail.gmail.com" type="cite" class="cite2">
<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 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 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 dir="auto"><br /></div><div dir="auto">Great regards </div><div dir="auto">RedIODev </div></div>
</blockquote></div>
</body></html>