Show HN: Dipstick – A new way to DI in TS
1 xxiem 0 6/27/2025, 9:41:10 PM github.com ↗
For whatever reason, every attempt at DI in this language that I've found over the last few years is more-or-less a port of an existing DI framework for languages like C# or Java/Kotlin, but they leave a lot to be desired. JS doesn't have TS types at runtime, so these frameworks tend to hack around that idea by muddying up source code with `@Decorators` or creating unique tokens to represent types. I personally find these hacks to be pretty ugly. What's worse, they violate the principle of least surprise (especially for devs who aren't familiar with DI), and they often result in code that's not type-safe!
Dipstick takes a totally different approach, which leverages the type system and code generation.
- Simple. There are only two concepts to learn about: Modules and Bindings. - Obvious. Want to see where a class is instantiated? Let your IDEs tools do the work. No tricky reflection or abstraction here -- just readable, generated code. - Modular. Define multiple modules and compose them together to keep code organized.
The framework is still really young, and currently only supports classes (boo), but if it gets some traction, I will update it to support injecting functions or other literal values.
I'd really love some feedback to make this thing better!
No comments yet