liveBook · Manning

ServiceRegistry

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

ServiceRegistry is Lamar's service-registration type for configuring registered services and their dependencies.

ServiceRegistry configures Lamar services inside an ASP.NET Core application. Pass it to UseLamar() to register application and framework services, then let Lamar build dependency trees when the application creates services. section 31.3

A practical setup follows these steps:

  • Install Lamar.Microsoft.DependencyInjection and call UseLamar() on WebApplicationBuilder.Host. section 31.3
  • Register framework services such as authorization and controllers through the ServiceRegistry. section 31.3
  • Use default conventions or assembly scanning to register concrete classes and conventionally named services. section 31.3
Listing 31.16 Configuring Lamar as a third-party DI container
builder.Host.UseLamar(services =>                    #1
{
    services.AddAuthorization();                     #2
    services.AddControllers()                        #2
        .AddControllersAsServices();                 #3
 
    services.Scan(_ => {                             #4
        _.AssemblyContainingType(typeof(Program));   #4
        _.WithDefaultConventions();                  #4
    });                                              #4
}
#1 Configures your services in UseLamar() instead of on builder.Services
#2 You can (and should) add ASP.NET Core framework services to the ServiceRegistry, as usual.
#3 Required so that Lamar is used to build your web API controllers
#4 Lamar can automatically scan your assemblies for services to register.

Shows a complete Lamar configuration, including framework services, controller activation, and assembly scanning. section 31.3

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

How deep it goes
Explains package setup, conventions, scanning, IServiceCollection compatibility, and controller activation, but defers advanced registrations.
Examples
Uses UseLamar(), AddAuthorization(), AddControllersAsServices(), and Scan() with default conventions.
What it assumes
Assumes an ASP.NET Core WebApplicationBuilder and teaches Lamar integration, framework-service registration, and convention-based discovery.
What you can do after
Apply Lamar through UseLamar() to register services and enable dependency-tree construction at runtime.
How it connects
Connects Lamar with dependency injection, IServiceCollection, WebApplicationBuilder, ASP.NET Core controllers, and assembly scanning.

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.