Skip to main content

Build-Time Dependency Injection Explained

ยท One min read
Vinit Shinde
Creator of Korus Framework

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:

  1. Scans your source code
  2. Builds an internal DI model
  3. Sorts beans with a topological algorithm
  4. Generates:
    • Constructor injection code
    • Method injection code
    • Singleton registries
    • Route metadata
    • A full KorusMain bootstrap 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);
}
}