Skip to content

fix(aspnetcore): begin the ambient tenant scope from a startup filter - #1240

Merged
AndrewTriesToCode merged 4 commits into
mainfrom
docs/v11-doc-fixes
Nov 19, 2026
Merged

AndrewTriesToCode merged 4 commits into
mainfrom
docs/v11-doc-fixes

Conversation

@AndrewTriesToCode

@AndrewTriesToCode AndrewTriesToCode commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes ahead of the v11 release.

Per-request tenant scope (fix(aspnetcore))

AddHttpAmbientTenantScope() used to decorate IHttpContextFactory to begin each request's ambient tenant scope. Replacing the default factory turns off ASP.NET Core's per-connection HttpContext reuse, so every request allocated a new HttpContext.

It now registers a TenantScopeStartupFilter ahead of all other startup filters. The filter's middleware begins the scope at the very start of the pipeline, so the scope still covers middleware added before UseMultiTenant<TId>() or by other startup filters. The scope is discarded when that middleware returns. IHttpContextFactory is left untouched.

TenantScopeHttpContextFactory was never released, so removing it is not a breaking change. The AspNetCore, Configuration and Usage, Core Concepts, Generic Host and Getting Started docs now describe the new mechanism.

Docs

  • Getting Started and Strategies called app.UseMultiTenant(), which no longer compiles. Both now use UseMultiTenant<string>() to match their AddMultiTenant<TenantInfo, string>() setup.
  • Fix the UseMultiTenant<strinG>() typo in Configuration and Usage.
  • Introduction now says .NET 11.
  • AGENTS.md now uses the .NET 11 SDK and net11.0, and its CI test commands now match ci.yml.

Testing

  • dotnet build -p:ContinuousIntegrationBuild=true: 0 warnings, 0 errors.
  • dotnet test: all pass (Core 331, AspNetCore 197, EFCore 159, Identity 91).
  • WebApiSample on Kestrel: 20 requests over one keep-alive connection, rotating through three tenants and one unknown identifier. Every response was in the right tenant's language, so no tenant leaked between requests.

🤖 Generated with Claude Code

AndrewTriesToCode and others added 3 commits November 18, 2026 21:53
Getting Started and Strategies showed app.UseMultiTenant(), which no
longer compiles now that only UseMultiTenant<TId>() exists. Also fix the
UseMultiTenant<strinG>() typo and update the Introduction to .NET 11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match the SDK, target framework and CI test commands to the net11.0
solution, including the coverage flag CI passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AddHttpAmbientTenantScope() decorated IHttpContextFactory to begin the
per-request scope. Replacing the default factory turns off ASP.NET
Core's per-connection HttpContext reuse, so every request allocated a
new HttpContext.

Register a TenantScopeStartupFilter ahead of all other startup filters
instead. Its middleware begins the scope at the very start of the
pipeline, so the scope still covers middleware added before
UseMultiTenant<TId>() or by other startup filters, and it is discarded
when the middleware returns. The IHttpContextFactory is left untouched.

TenantScopeHttpContextFactory was never released, so removing it is not
a breaking change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AndrewTriesToCode AndrewTriesToCode changed the title docs: fix UseMultiTenant snippets and update .NET 11 references fix(aspnetcore): begin the ambient tenant scope from a startup filter Nov 19, 2026
Cover that the ambient tenant scope begun by the startup filter is still
active for Response.OnStarting callbacks and has ended before
Response.OnCompleted callbacks run. The test for the removed
IHttpContextFactory decorator covered when the scope ended, and nothing
had replaced it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AndrewTriesToCode
AndrewTriesToCode merged commit cada517 into main Nov 19, 2026
5 checks passed
@AndrewTriesToCode
AndrewTriesToCode deleted the docs/v11-doc-fixes branch November 19, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant