liveBook · Manning

IServiceCollection

As explained in ASP.NET Core in Action, 3e

IServiceCollection is the ASP.NET Core abstraction representing the collection of service registrations available to an application.

IServiceCollection is the application’s list of known service registrations. WebApplicationBuilder exposes it through builder.Services, allowing the dependency-injection container to provide services when application classes declare dependencies. section 3.7.1 section 8.4

Use the collection to:

  • Register framework features such as Razor Pages and authentication through extension methods. section 8.4
  • Register application services, such as a tax calculator, so the container can supply them to dependent classes. section 3.7.1
  • Finish registration before calling Build(); afterward, the application’s service definitions cannot be changed. section 3.7.1

Registering Razor Pages

WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); WebApplication app = builder.Build(); app.MapRazorPages(); app.Run(); AddRazorPages() registers the services required by Razor Pages, while MapRazorPages() registers their endpoints. Omitting the service registration causes the application to fail when it starts. section 8.4

builder.Services.AddHttpLogging(opts =>
   opts.LoggingFields = HttpLoggingFields.RequestProperties);

Inspect a compact example of configuring HTTP logging services through an IServiceCollection extension method. section 3.7.1

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains registration, extension methods, dependency resolution, and the Build boundary without detailing container internals.
Examples
Uses AddHttpLogging(), AddRazorPages(), custom services, and the Build() boundary as concrete examples.
What it assumes
Assumes basic Program.cs and WebApplicationBuilder familiarity while introducing dependency injection and service registration.
What you can do after
Apply it via WebApplicationBuilder.Services to register framework features and application dependencies before building the app.
How it connects
Connects dependency injection, WebApplicationBuilder, extension methods, Razor Pages, authentication, and middleware.

Also explained in

Compare how 2 books explain IServiceCollection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.