Table of Contents

Hooks

Description

Callbacks for hooking into framework startup — register services, extend the middleware pipeline and react to host events.

Features

  • Service registration: OnConfigureServices — register your own services alongside framework services
  • Pipeline hooks: tap into the request pipeline at specific points
  • Host lifecycle hooks: react to host building, built and started events

Behavior

Service hook:

OnConfigureServices(services, env)  → called during service registration

Pipeline hooks (called per branch — Web, Static, Api):

OnPipelineBegin    → after rate limiter and block middleware, before all others
OnBeforeEndpoints  → called before controllers and routes are mapped
OnAfterEndpoints   → called after controllers and routes are mapped — add extra endpoints here
OnPipelineEnd      → after pipeline is fully built

Host lifecycle hooks:

OnHostBuilding  → configure host (logging, DI, etc.)
OnHostBuilt     → read final host configuration
OnHostStarted   → app is live — perform warmup, seed data, start background jobs

Caveats

  • All hook methods have default empty implementations — only override what you need
  • IFrameworkHooks is not invoked when using the Framework Extension API — use extension methods directly in that case
  • OnAuthorization requires both UseAuthentication and UseAuthorization to be true in FrameworkOptions
Tip

Use OnHostStarted for warmup tasks like pre-loading cache or seeding data — the host is fully live at that point and all services are available.