3 ms·
Your criticisms seem to only apply to runtime dependency injection frameworks. That's why I like Dagger, and recommended it elsewhere in this thread; it's comp
by CydeWeys 10y ago
Your criticisms seem to only apply to runtime dependency injection frameworks. That's why I like Dagger, and recommended it elsewhere in this thread; it's compile-time dependency injection. So you do get type safety, the compiler does check that you have satisfied all dependencies, etc. Check it out if you haven't used it before.
- benjiweber 10y agoYou're right, most of the downsides are specific to runtime wiring. I haven't used dagger. It does compile time magic doesn't it?
- CydeWeys 10y agoYes. If you do something wrong in your wire-up then the code won't even compile. Definitely look into it. Like you, I have a healthy distrust of DI frameworks because of the many errors that get pushed to runtime, but Dagger's not bad.
- beder 10y ago(Disclosure: I work on Dagger in my 20% at Google.) What's more, Dagger gives you (compile-time) insights into the graph of dependencies. For example, we've hooked up our internal code-search tool to give you Dagger cross-references, so if you (e.g.) click on a parameter to an @Inject constructor, you'll see the place that provides that object. Also, if you click on the @Component, you'll see a visualization of the entire graph. We're working on surfacing these hooks in the open source repo, which would allow IDEs like Eclipse to gain this functionality as well.