Wiki 9Minecraft Wiki 9Minecraft

Set Up Dependency Injection in Your Mod

Java EditionModGuides 4FAQ 10Related mods 60
DownloadAnnotated DI Mod

Get the files on 9Minecraft

Contents (3)
  1. Understanding the Injector
  2. Basic Setup
  3. Using Injected Classes

Understanding the Injector

Annotated DI Mod provides a central injector for your mod that automatically wires dependencies together. This replaces manual object creation and passing with clean, annotation-based injection.

Basic Setup

1. Create an injectable class by adding the @ImplementedBy annotation to your interface or class. This tells the injector how to instantiate it.

2. Access the injector through the mod's central injector instance. Each mod using Annotated DI gets its own injector automatically.

3. Request instances by calling the injector's injection methods with your class. The injector resolves all nested dependencies automatically.

Using Injected Classes

Once set up, you can request instances anywhere in your mod's code. The injector handles creating objects and satisfying their dependencies without you writing factory code or configuration files. This keeps your codebase organized and makes it easier to swap implementations later for testing or features.

More guides for this mod