Menu

The forgotten Where clause: claim-based multi-tenancy for ASP.NET Core and EF Core
πŸ“°

The forgotten Where clause: claim-based multi-tenancy for ASP.NET Core and EF Core

DEV Community: opensourceΒ·olosunde KehindeΒ·21 days ago
#A2LtyA1i
#devtoopensource#devto#dev#modelhub#multitenancy
Long article (287 words) β€” no AI summary yet.
Reading 0:00
15s threshold

I've just released an open-source .NET library: ModelHub.MultiTenancy πŸŽ‰

Every multi-tenant SaaS has the same lurking bug: one query without a tenant filter, and one customer can see another customer's data.

While building StrideWell on my own (close to 100 database tables and 600+ API endpoints), I couldn't rely on remembering that filter every time. So I built the protection into the data layer:

βœ… The tenant comes from the user's login token

βœ… Every database query is filtered to that tenant automatically

βœ… Saves that would touch another tenant's data are refused

βœ… Branch-level access (a receptionist sees their own clinic only)

βœ… Support staff can act as a customer, with every access logged

Today I extracted it, tested it on .NET 8 and .NET 10, and published it on NuGet under ModelHub Solutions.

The write-up walks through a worked example of a vet practice SaaS. Link in the comments πŸ‘‡

If you build multi-tenant apps in .NET, I'd really value your feedback, and contributions are welcome.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.