Dependency Injection: Decoupling Systems

Dependency Injection (DI) is a design pattern that implements Inversion of Control (IoC), allowing components to receive their dependencies from an external assembler rather than creating them internally.

1. Core Injection Modalities

2. Lifecycles and Scoping

The IoC container manages the lifetime of the injected objects: | Scope | Description | Use Case | | :--- | :--- | :--- | | Singleton | One instance per container. | Stateless services, database pools. | | Transient | New instance created for every injection. | Lightweight, stateful objects. | | Request/Session| One instance per HTTP lifecycle. | User context, authentication tokens. |

3. Concrete Implementation: Google Guice

In the Wikantik codebase (GEMINI.md), we use Guice for DI.

4. Why DI? (The Testing Argument)

The primary value of DI is testability.


See Also: