question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Idea] - scrap tenant resolver middleware

See original GitHub issue

Just 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:

  1. 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:

  1. TenantResolutionMiddleware can be dropped meaning less step for consumer.
  2. People can inject the ITenantAccessor service whenever they need to access current Tenant (rather than inject TenantContext or TTenant.
  3. 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:closed
  • Created 6 years ago
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
benfostercommented, Jul 25, 2017

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found