Dependency Injection

Kasper Nielsen kasperni at gmail.com
Mon Feb 20 20:56:14 UTC 2023


On Mon, 20 Feb 2023 at 20:25, Remi Forax <forax at univ-mlv.fr> wrote:
>
> ----- Original Message -----
> > From: "Kasper Nielsen" <kasperni at gmail.com>
> > To: "Red IO" <redio.development at gmail.com>
> > Cc: "amber-dev" <amber-dev at openjdk.org>
> > Sent: Monday, February 20, 2023 8:57:20 PM
> > Subject: Re: Dependency Injection
>
> >> Suggestion:
> >> I was wondering if this concept would be interesting to incorporate into the jdk
> >> as an expansion of the ServiceLoader api.
> >>
> >
> > I think the practical use cases for this are going to be very limited.
> > ServiceLoader always creates a new service per request. So if both B and C
> > depend on A. Two instances of A will be created. Which is rarely what
> > you want when you are composing an application.
>
> It depends if you implement the static method provider or use the default constructor.

Of course, you could cache the instance in the static method provider.
But that is even more code. On top of all the managing of individual services
in META-INF/services or module-info.java you also need to do.

/Kasper

/Kasper


More information about the amber-dev mailing list