Build-Time Dependency Injection Explained
Most Java frameworks use runtime DI, where objects are created and wired when the application starts.
This works โ but it's slow, unpredictable, and memory-heavy.
Korus takes a different approach:
All dependency injection is generated at compile time.
No reflection.
No proxies.
No classpath scanning.
Why Build-Time DI?โ
Build-time DI solves three major problems:
Slow Startupโ
Runtime DI frameworks scan the classpath and perform reflection when the app boots.
Korus eliminates this entirely.
Hidden Runtime Errorsโ
Many DI issues (circular dependencies, missing beans) are discovered only when you run the app.
Korus validates the entire DI graph at compile time.
Large Memory Footprintโ
Reflection metadata, runtime registries, proxies โ all reduce performance.
Korus generates pure Java code instead.
How Korus Generates the DI Graphโ
During compilation, the Korus processor:
- Scans your source code
- Builds an internal DI model
- Sorts beans with a topological algorithm
- Generates:
- Constructor injection code
- Method injection code
- Singleton registries
- Route metadata
- A full
KorusMainbootstrap class
Everything is resolved before your application even runs.
Example Generated Code (Simplified)โ
public final class UserService$$KorusBean {
private final UserRepository repo;
public UserService$$KorusBean(UserRepository repo) {
this.repo = repo;
}
public UserService get() {
return new UserService(repo);
}
}
