Skip to main content

What is the scope of a dependency?

The scope of a dependency is a rule that determines how long an object created by the dependency container lives and when it gets recreated.

Examples:

  • Singleton - created once for the entire lifetime of the application; everyone gets the same instance.
  • Scoped - lives within a single request or context (for example, an HTTP request in a web application).
  • Transient - created anew every time it is requested.

In other words, scope governs the lifetime of dependencies and who "kills" them.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.