Skip to content

Add lightweight EF Core tenant guardrails sample - #24

Merged
balajibashyam merged 3 commits into
mainfrom
feature/ef-core-tenant-guardrails-sample
Aug 17, 2026
Merged

Add lightweight EF Core tenant guardrails sample#24
balajibashyam merged 3 commits into
mainfrom
feature/ef-core-tenant-guardrails-sample

Conversation

@balajibashyam

Copy link
Copy Markdown
Contributor

Summary

Adds a minimal .NET 10 companion sample for the EF Core 8 Multi-Tenancy: Tenant Isolation, Soft Deletes, Audit Trails & Query Filters tutorial.

The tutorial is EF Core 8-era and broad; this companion is EF Core 10 and narrowly answers: how can EF Core make shared-table tenant reads fail closed, keep soft-delete bypass tenant-safe, reject cross-tenant writes, and prove those guardrails against one relational database containing multiple tenants at the same time?

What's included

  • New sample: ef-core/multitenancy-softdelete-auditing/ — 13 files

    • Validated, trusted TenantExecutionContext injected into every DbContext
    • Fail-closed named TenantFilter (always active)
    • Named SoftDeleteFilter with selective bypass that keeps the tenant filter active
    • Composite primary key TenantId + Id so alpha/1 and beta/1 coexist
    • SaveChangesInterceptor (sync + async) that overwrites insert tenant, rejects cross-tenant mutations, stamps creation/update audit, and converts Remove() to a narrow soft-delete update
    • One shared SQLite in-memory database hosting both alpha and beta tenants
    • 8 deterministic xUnit v3 integration tests
  • Root README: New sample row in the table + updated repository structure tree

  • GitHub Actions: New test-ef-core-tenant-guardrails job in the shared workflow; path filters updated for push and pull_request

Deliberately omitted (stays in the full tutorial)

HTTP tenant resolution, subdomain parsing, JWT/authentication, tenant membership lookup, platform-admin all-tenant access, background jobs, hard delete, GDPR workflows, PostgreSQL RLS / SQL Server security policies, migrations, compiled queries, ExecuteUpdate/ExecuteDelete, Minimal APIs, repositories, Testcontainers, benchmarks.

Versions

  • .NET SDK: 10.0.302
  • Microsoft.EntityFrameworkCore.Sqlite: 10.0.11 (only direct app package)
  • xunit.v3 3.2.2, xunit.runner.visualstudio 3.1.5, Microsoft.NET.Test.Sdk 18.8.1

Validation

  • dotnet restore — passed
  • dotnet build --configuration Release — passed (0 errors, 0 warnings)
  • dotnet test --configuration Release — passed (8/8)
  • App output matches the exact six-line expected block
  • Security scan — clean
  • No generated SQLite database artifacts

@balajibashyam
balajibashyam merged commit 3ef3076 into main Aug 17, 2026
26 checks passed
@balajibashyam
balajibashyam deleted the feature/ef-core-tenant-guardrails-sample branch August 17, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant