Does dependency injection potentially cause large overhead?
I would imagine so, especially if the resolver is called many times (which is quite likely looking at pattern examples)? Or am I thinking wrong? Unfortunately I can't test for myself as I have never used it but planned on using it.
Unless you're using a service locator, I doubt that the overhead will make a significant difference. (Even if you are, it's unlikely to be significant.)
Using constructor injection and a modern framework, the resolver will get called when objects are constructed. For the most part I suspect you'll find that the objects with dependencies are relatively high-level components, long-lived, or both.
If you're using an IoC container and creating a lot of objects with dependencies in a tight loop, you might need to do some optimization. You could always profile or benchmark it.
In short, I wouldn't worry about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With