Dependency Injection Container — RexDac Academy

RexDac AcademyTechnical notes · Some prior knowledge helps
0%Published notes read · this device

Principles and Architecture / Dependency Injection

Dependency Injection Container

Original notes by SunDiaL · View English source

A DI Container is Indirection applied to the Composition root, and it becomes the Creator in GRASP. It is a class whose purpose is to manage dependencies and their lifetimes.

Object Lifetime Scope

Lifetime Scope is extending the meaning that Scope had for simple variables. The meaning shifts from "how long is a variable alive/visible" to "what kind of life should this dependency (object/class) have". "Life" here means "instancing strategy":

  • Singleton = The same instance for all classes
  • Scoped = A different instance per "scope" (scope here can mean a web request, an event handler, whatever else. It depends on your context)
  • Transient = A different instance for all classes