liveBook · Manning

Service container

As explained in Building Web APIs with ASP.NET Core

A service container is a registry and runtime that stores service definitions, creates or reuses service instances, and manages their lifetimes.

A service container is a registry and runtime for application services. In ASP.NET Core, the built-in IServiceProvider stores service registrations, creates or reuses instances, manages configured lifetimes, and disposes dependencies when they are no longer needed. section 1.2.1

A typical service-container workflow has three practical steps:

  • Implement each service behind an interface or base class, using framework, application, or third-party implementations. section 1.2.1
  • Register and configure services in Program.cs, choosing Transient, Scoped, or Singleton lifetime behavior. section 1.2.1
  • Request services through a class constructor; the framework supplies a new or existing instance according to its lifetime. section 1.2.1

Framework-provided services

An application can register and inject services such as IAuthorizationService for policy-based permissions or IEmailService for sending email messages. section 1.2.1

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains interfaces, registration, injection, lifetimes, reuse, and disposal, while stopping short of container internals.
Examples
Uses IAuthorizationService for policy-based permissions and IEmailService for sending email messages.
What you can do after
Apply it via ASP.NET Core's IServiceProvider and constructor injection to configure and consume application services.
How it connects
Connects dependency injection with inversion of control, interfaces, service lifetimes, and middleware.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.