0

I am developing a multi tenancy web app in .NET 6. I have so far got to a point where my main app will have all the default controllers, views, view components etc.

I have also got a separate class library per tenant where I can override view components etc, my app is finding the tenant specific view component fine, but when it tries to return the view from another one of the tenants which is registered, probably because I have registered multiple assemblies with embedded view components which all have the same path.

What direction should I be looking into to make this tenant aware and to find the correct view?

If you need anything more specific let me know I'll add in the comments / update the question.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Paul Hinett
  • 1,951
  • 2
  • 26
  • 40
  • _"a separate class library per tenant"_ - uhhh, please explain what you mean by that (because that sounds absolutely hellish - and means that you have a funny definition of what multi-tenancy means...). – Dai Nov 17 '22 at 10:27
  • Well its an app i own and develop for a small number of clients (5-10), but each client may need slightly different options and info displayed in specific parts of the app. So am looking for a way to keep there view components separate from the main default app. If the app finds a custom view component for the current tenant it will load and use this one instead. In v1 of my app (.net 4.6) it was all a bit of a mess and all inside the main app. – Paul Hinett Nov 17 '22 at 10:36
  • If your clients really need that level of customization then I think you'd be better-off by using a per-tenant deployment (though you _can_ still use a shared/single database provided there's no per-tenant database customization - I trust you're using composite-keys to reduce the risk of cross-tenant data exposure?). – Dai Nov 17 '22 at 10:37
  • data is kept in separate databases, there is no risk of data being shared between tenants, to access anything they need to be authenticated too. The main app would cover 90% of use cases, its like 10% that would be custom. When you say per tenant deployment do you mean a full separate project per tenant? If so i don't see this being an option as changes on the 90% side that should affect all tenants would create much more work. – Paul Hinett Nov 17 '22 at 10:42
  • No, I mean separate IIS Websites or Azure App Service instances. (They can still share the same hostname, in IIS use ARR, in Azure use App Gateway). – Dai Nov 17 '22 at 10:43
  • Oh yes this is fine, but the original question still stands on how would my project find a tenant specific view for a view component at runtime if the views are embedded. I am just toying around with placing my views in a /{tenantName}/views/components/XComponent/Default.cshtml folder format, and have my main app check for tenant specific folders first. – Paul Hinett Nov 17 '22 at 10:45
  • You'd have to have a custom deployment system that copies the right per-tenant dependencies over, and sets a per-site config (`appsettings.json` or an environment variable, for example) that tells the application where to get those per-tenant files from. – Dai Nov 17 '22 at 10:47
  • I like the idea, just thinking about development time though it wouldn't work well as there is no way to debug before deploying – Paul Hinett Nov 17 '22 at 10:52
  • Why wouldn't you be able to debug? – Dai Nov 17 '22 at 10:53
  • maybe i dont understand what you mean, when you say custom deployment system, are you meaning that when deploying to production it would find tenant specific views and copy them to the main app for that tenant? If so then how do i run my app locally in development for a specific tenant? – Paul Hinett Nov 17 '22 at 10:56
  • When running locally you would have all the view files for _all_ tenants on your machine, right? So just set the per-Tenant settings in `appsettings.json` in VS for the Tenant you want to debug under. – Dai Nov 17 '22 at 11:00

0 Answers0