this post was submitted on 02 May 2024
401 points (92.8% liked)
Programmer Humor
19555 readers
434 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I don't think so. When I've seen it done it's usually not been random values injected (except when those values are secret keys which should absolutely not be stored in code to begin with), it's usually injecting a service. Another class, usually with a name that makes it easy to trace down. Like if you're building an
OrderService
, that might take as a dependency anIProductService
, which would have injected into it the classProductService
(personally, I don't like the Hungarian notation that C# uses, but it's a convention and my preference for sticking to strong conventions for the sake of consistency outweighs my distaste for Hungarian notation). That's easy to find, and in fact your IDE can probably take you straight to it from theOrderService
's constructor.I'm using value in the loosest sense, like how all objects are values.
So now if you have three implementations of
IProductService
, how do you know which one is configured?It's easy to imagine a hypothetical way that could lead to problems. But in all the code I've worked with, either that scenario is avoided entirely, or other context makes it absolutely clear which
IProductService
is being used.