service registration
Telling the dependency injection container which implementation, with which lifetime, should satisfy requests for a service type.
In more detail
builder.Services.AddScoped<IOrderReader, OrderReader>() maps the abstraction on the left to the implementation on the right. Registrations happen at startup, before the host is built.
Related terms
- dependency injection — Giving an object the collaborators it needs from outside, usually through its constructor, instead of letting it create or look them up itself.
- IServiceCollection — The list of service registrations the dependency injection container is built from, reached in ASP.NET Core as builder.Services.
- service lifetime — How long the container keeps and reuses an instance of a service: transient, scoped or singleton.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- The Dependency Injection Container: Scopes and Lifetimes — Modern .NET Core, C# & Enterprise Microservices
- The Options Pattern: Strongly Typed Configuration — Modern .NET Core, C# & Enterprise Microservices