News for hackers. Stuff that matters.
Re:You probably don't need a dependency injection framework by surgical_fire on Sunday May 25, 2025 @06:26AM (#44086838)
> DI just becomes a fancy name for "creating instances" and "passing parameters".

I literally addressed this in the post you are replying to. I think your problem is reading comprehension, not dependency injection or framework usage.

Then again, understanding Design Patterns will be difficult if you can't even parse you way through a handful of paragraphs written in plain English.

I'll bother to repeat myself:

>> This can be done manually, but becomes a chore super fast - and will be a very annoying thing to maintain as soon as you change the constructor of something widely used in your project to accept a new parameter.

>> Frameworks typically just streamline this process, and offers some flexibility at times - for example, when you happen to have different implementations of the same thing. I find it funny that people rally against those Frameworks so often.

There. Maybe stripped of the surrounding context will make it easier.

> I’d rather be unemployed than work with Spring.

That's really a you problem.

Re:You probably don't need a dependency injection framework by thiht on Sunday May 25, 2025 @07:00AM (#44086966)
No need to be aggressive, I just disagree that DI frameworks streamline anything, they just make things more opaque and hard to trace.

> will be a very annoying thing to maintain as soon as you change the constructor of something widely used in your project to accept a new parameter.

That for example is just not true. You add a new parameter to inject and it breaks the injection points? Yeah that’s expected, and suitable. I want to know where my changes have any impact, that’s the point of typing things.

A lot of things deemed "more maintainable" really aren’t. Never has a DI framework made anything simpler.

Re:You probably don't need a dependency injection framework by surgical_fire on Sunday May 25, 2025 @08:08AM (#44087232)
> That for example is just not true. You add a new parameter to inject and it breaks the injection points?

Perhaps you never worked in a sufficiently large codebase?

It is very annoying when you need to add a dependency and suddenly you have to touch 50+ injection points because that thing is widely used. Been there, done that, and by God I wished I had Dagger or Spring or anything really to lend me a hand.

DI frameworks are a tool like any other. When properly used in the correct context they can be helpful.

Re:You probably don't need a dependency injection framework by culturedsystems on Sunday May 25, 2025 @05:22PM (#44091256)
"It is very annoying when you need to add a dependency and suddenly you have to touch 50+ injection points because that thing is widely used"

You don't have to update the injection points, because the injection points don't know the concrete details of what's being injected. That's literally the whole point of dependency injection.

Edited to add: Say you have a class A, and this is a dependency of classes B, C, etc. Using dependency injection, classes B and C are passed instances of A, they don't construct it themselves. So if you add a dependency to A, you have to change the place that constructs A, of course, but you don't have to change B and C, because they have nothing to do with the construction of A.

Re:You probably don't need a dependency injection framework by therealdrag0 on Sunday May 25, 2025 @07:41PM (#44092369)
Ya very confused by this. Either the change is to the constructor of the object being injected, in which case there is no difference either way, or the change is to the constructor receiving the injection, in which case there’s no difference either way.
Re:You probably don't need a dependency injection framework by cornel_io on Sunday May 25, 2025 @07:15PM (#44092186)
I think you're being downvoted because you're agreeing with the post you're quoting, but arguing as if they're wrong: the example in question was there to show how DI can be useful, so there's nothing to argue against.
Re:You probably don't need a dependency injection framework by layer8 on Sunday May 25, 2025 @05:53PM (#44091539)
This is the only reason why DI frameworks exist. However, this issue can be largely avoided by working with configuration objects (parameter objects [0]) from the start, that get passed around. Then you only need to apply the change in a small number of parameter-object classes, if not just a single one.

[0] https://wiki.c2.com/?ParameterObject

Re:You probably don't need a dependency injection framework by jcelerier on Monday May 26, 2025 @09:14AM (#44097143)
Eh, having built a whole codebase around these configuration objects I really regret not going for more traditional DI IoC container. It's thousands over thousands of additional parameters passed all over the place when creating objects just for the sake of saving five minutes of explanation to newcomers.
Re:You probably don't need a dependency injection framework by baq on Sunday May 25, 2025 @04:34PM (#44090861)
The one thing DI frameworks unarguably and decisively solve by design (if accidentally, but it doesn’t matter) is control over static initialization. I’d say you haven’t truly lived if your C++ didn’t crash before calling main(), but it helps in large JS and Python projects just the same.
Re:You probably don't need a dependency injection framework by layer8 on Sunday May 25, 2025 @05:48PM (#44091502)
How do they solve that? If constructors require certain parameters, someone has to pass them. If it’s not a top-level object, the instantiating code will pass it and have a corresponding constructor or method parameter itself. At the top level, main() or equivalent will pass the parameter. Where is the problem?
Re:You probably don't need a dependency injection framework by baq on Monday May 26, 2025 @05:48AM (#44095711)
Exactly, there is no problem when you do it this way and DI frameworks force you to.

The problem when you don't do it this way is when you depend on order of initialization in a way you are not aware of until it breaks, and it breaks in all kinds of interesting ways.

Re:You probably don't need a dependency injection framework by babyent on Sunday May 25, 2025 @05:04PM (#44091114)
Chill dawg
Re:You probably don't need a dependency injection framework by tomhow on Monday May 26, 2025 @10:29AM (#44097764)
Be kind. Don't be snarky. Converse curiously; don't cross-examine. Edit out swipes.

When disagreeing, please reply to the argument instead of calling names. "That is idiotic; 1 + 1 is 2, not 3" can be shortened to "1 + 1 is 2, not 3."

Please don't fulminate. Please don't sneer, including at the rest of the community.

https://news.ycombinator.com/newsguidelines.html