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

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

1 points akardapolov 1 year ago 0 comments

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton