ddi
Made in the European Union
Version 06.01.01 · JDK 21+ · EUPL 1.2

Dependency Injection
that decides at call time.

DDI lets plain Java logic pick the implementation on every @Inject. Pricing tiers, quotas, roles, feature flags, multi-tenancy, mocks — without a single if in your domain code.

Resolver — runs on every @Inject
@ResponsibleFor(ReportGenerator.class)
class ReportPolicy implements ClassResolver<ReportGenerator> {
  public Class<? extends ReportGenerator> resolve(Class<ReportGenerator> i) {
    var user = SecurityContext.current();           // e.g. jSentinel
    if (user.quotaExceeded())   return ThrottledReport.class;
    return switch (user.plan()) {
      case FREE       -> BasicReport.class;
      case PRO        -> FullReport.class;
      case ENTERPRISE -> FullReportWithSLA.class;
    };
  }
}

Why DDI

A nano library with one big idea: cross-cutting decisions belong in the resolver, not in your services.

When is the implementation chosen?

Classic DI containers bind at startup. CDI matches qualifiers statically. DDI hands the decision to your own code — every single time the field is injected.

How ClassResolver works →
FrameworkBound when?Runtime change?
SpringContainer refreshProfile flip + restart
GuiceInjector buildNew injector
CDI / WeldQualifier match (static)Hard-coded in annotation
DDIPer @Inject lookupYour own Java logic

Drop it into your build

  • JDK 21+, runs in any plain-Java process — CLI, Lambda, Vaadin, JavaFX.
  • Five public classes in the core. No container, no XML.
  • Reflections-based classpath scan; bootstrap is one method call.
  • Licensed under EUPL 1.2 — friendly to commercial use.
Maven coordinates
<dependency>
  <groupId>com.svenruppert</groupId>
  <artifactId>ddi</artifactId>
  <version>06.01.01</version>
</dependency>
Bootstrap
DI.activatePackages("com.example");
MyService svc = DI.activateDI(MyService.class);
Consulting

Plan-aware architecture, done right

Workshops, architecture reviews and pair-programming for teams introducing per-user / per-plan logic into Java backends — without rewriting their domain layer.

Learn more →
Sponsoring

Support continued maintenance

DDI is open source. Sponsoring keeps releases predictable and the roadmap public.

Become a sponsor →