top | item 45821919

Show HN: Lightweight Runtime DI for Java Using Class-File API and JSR-330

1 points| akardapolov | 3 months ago |github.com

Built a compact DI container for Java that avoids the pain points of Dagger 2's compile-time graph generation and the overhead of Spring/Guice's runtime reflection.

A key insight, suggested by Gemini and several other LLMs, is to use JDK 24's Class-File API for zero-reflection classpath scanning, and then MethodHandles for fast object instantiation. The solution is JSR-330 compliant.

Migrated a real project (Dimension-UI) from Dagger 2 in 2 days. Key improvements: - No bytecode generation or proxying magic - Actual testability (isolated unit tests now work) - 19KB footprint vs 10MB+ for Spring - Startup is instant

Links

Dimension‑DI: https://github.com/akardapolov/dimension-di Dimension‑UI: https://github.com/akardapolov/dimension-ui

DI Containers Comparison: https://github.com/Heapy/di-comparison

discuss

order

No comments yet.