Michael Long
Jan 7, 2025

--

The flip side to the argument is that constructor injection just kicks the can down the road and complicates the caller.

Sure, MyService gets the repository that it needs, but someone needs to make MyService, and from where did it obtain the repository instance to pass into the constructor?

Further, initialization lists can get long and complicated depending upon the needs of the serivce.

The "helper" solution mentioned doesn't fix things either. Previously I had to scan the object looking for @Autowired, but now I don't have to do that!

With @RequiredArgsConstructor, all I have to do is scan the object looking for every instance of final.......

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet