Back to Developer Roadmap

Dependency Injection

src/data/roadmaps/server-side-game-developer/content/dependency-injection@uTlxyDOtvt_Qp0gXLWO-j.md

4.0710 B
Original Source

Dependency Injection

Dependency Injection (DI) is a programming technique that makes a class independent of its dependencies. This is achieved by decoupling the use of an object from its creation. In this technique, instead of a class creating an object itself, an object is supplied or "injected" to the class by an external entity. The actual creation and binding of dependencies are managed by a 'container', which injects the dependencies into the respective classes. Dependency Injection can be done in three ways: Constructor Injection, Setter Injection, and Interface Injection. Each of these methods involves moving the responsibility of the object creation and binding to another class or method.