[Idea] - scrap tenant resolver middleware
See original GitHub issueJust an idea that I ended up implementing recently myself and seemed to work quite well. Consider this middleware: https://github.com/saaskit/saaskit/blob/master/src/SaasKit.Multitenancy/Internal/TenantResolutionMiddleware.cs
You can scrap this middleware entirely if:
- Replace it with a “scoped” service, that does exactly what the middleware does, but in a
Lazy<TTenant>
such that the tenant is lazily resolved on first access of the Tenant property / method.
I think this then simplifies things a bit because:
- TenantResolutionMiddleware can be dropped meaning less step for consumer.
- People can inject the
ITenantAccessor
service whenever they need to access current Tenant (rather than injectTenantContext
orTTenant.
- You can change the implementation of ITenantAccessor so that it doesn’t need to store the TenantContext in httpcontext - because its already a scoped service, it can just keep the TenantContext directly as a property. This means you could also remove the extensions methods for httpcontext that Get / Set the TenantContext from httpcontext - as it would no longer be stored there - it would be held on the ITenantAccessor, which unlike the middleware, is accessible anywhere the tenant needs to be accessed.
Issue Analytics
- State:
- Created 6 years ago
- Comments:21 (5 by maintainers)
Top Results From Across the Web
The Ultimate Guide for Laravel Multi Tenant with ...
A while ago I wrote an article called Simple Multi Tenant with Laravel. ... Laravel will try to resolve the CompanyFactory.
Read more >Multi-tenant ASP.NET Core app - tenant resolution - brokul.dev
We need to set the tenant in TenantContext in the HTTP pipeline. Let's create custom middleware with tenant resolution logic. It gets the...
Read more >Multi-tenant Apps With EF Core and ASP.NET Core
An ASP.NET Core middleware that reads and sets the tenant based on the parameter; An EF Core DbContext that uses the tenant to...
Read more >Multi Tenancy | Documentation Center | ABP.IO
Multi-Tenancy is a widely used architecture to create SaaS applications where the hardware and software resources are shared by the customers (tenants).
Read more >How to build a multi-tenant applications with ASP.NET Core
In this article, I will discuss multi-tenant web applications and step-by-step ... This Tenant middleware will call with every HTTP request.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dazinator I’m in the process of upgrading SaasKit to csproj and then will look at some of the items we discussed. It would be good if we could incorporate your ideas into SaasKit - I’ll have a look through your code tomorrow.
Inject
Task<TTenant>
seems to work nicely: https://github.com/dazinator/Dotnettency/commit/a15eaa05566abe7efdef1e3468974da88869fee9#diff-dcaa3e511ec5996c9946ae81b027c8d1R16