Scoped

In .NET, scoped services are used to share stateful resources or services within a specific context, such as a web request or unit of work.

Scoped services are useful for:

  1. Maintaining Consistency

    • Scoped services are valid for the duration of a request, which helps maintain consistency.

  2. Managing Resource Utilization

    • Scoped services help manage resource utilization and isolation during the processing of HTTP requests.

  3. Sharing Data

    • Scoped services are beneficial when multiple objects in a single scope need to share data or communicate.

The AddScoped method in ASP.NET Core's built-in service container creates a new instance of a service for each request to the application. This ensures that each request or operation has its own isolated instance, preventing interference between different contexts.

Last updated