Skip to content

Register BOL services

Consumers call RegisterBolServices once during service configuration so that every page model, view component, and facade in the library can be resolved. BolRazorLayoutStartup calls it automatically.

Field Value
Operation ID OP-01
Trigger Application startup calling RegisterBolServices
Inputs IServiceCollection
Outputs The same collection with BOL registrations added
Primary components BolServiceExtensions.RegisterBolServices
Entry point src/BolMiddleware/Extensions/BolMiddlewareExtensions.cs

Steps

  1. Add ASP.NET Core session services with AddSession().
  2. Register the four internal API client packages by chained calls: BOL Context, BOL Menu, Policy Header, and Policy Core clients.
  3. Register IHttpContextAccessor as a singleton.
  4. Register ISecurityService as scoped, and IWebContextService, IMenuService, and IPolicyHeaderService as singletons.
  5. Register IBolContextApiClient as a singleton a second time; it repeats the registration made in step 2 and the last registration wins.
  6. Register IBolServicesContainer and ICookieService as scoped and IContextCookieHelper as a singleton.
  7. Return the collection for chaining.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([RegisterBolServices]) --> S1[AddSession]
    S1 --> S2[Register four API clients]
    S2 --> S3[Register accessor and facades]
    S3 --> S4[Register duplicate Context client]
    S4 --> S5["Register container, cookie service, helper"]
    S5 --> EndOk([Return IServiceCollection])

Failure and edge-case behavior

  • UseSession() and a distributed cache are not configured here; a consumer without them fails at runtime when session is first used, unless the base startup supplies them**.
  • Singleton facades depend on API clients whose lifetimes are set inside the client packages; a lifetime capture risk is unknown**.
  • The duplicate IBolContextApiClient registration is redundant and may hide a differently configured client from the client package.

Note: Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • src/BolMiddleware/Extensions/BolMiddlewareExtensions.cs
  • src/BolMiddleware/BolRazorLayoutStartup.cs