3
votes

I am developing a multi-tenant application using ASP.NET MVC, and after doing a good research on multi-tenancy and SaaS I have found there are many resources available to implement data layer (database: separation by Schema, by database or shared) but very limited resources are available to implement Business and UI layer though.

I have picked up separate database approach.

Now in order to make it truly multi-tenant I have chosen plugin based architecture (like umbraco and Nopcommerce) where plugin is an MVC application with tenant based model, view and controller.

Here is how I am going to develop it:

  • Controller factory will be initialized based on tenant (subdomain)

  • Business layer will be injected (using DI) based on tenant.

  • and UI (View) will be rendered based on plugin.

But in this way everything is being redundant, not able to share common behaviour.

Can anyone help to design it the way I can share common behaviour or is there any better approach doing so?

1
please define the problem faced, like how to have a common behavior in the UI / controller. It would not be easy to maintain separate UI / controller for each Tenant, given that you onboard a tenant and the tenant will have to wait for a deployment update for this workspace to be setup. This is not the purest multi-tenancy level. share your explicit problem and solution can be suggested. - Saravanan
Hi @Seravanan, thanks for your comment. You are correct that for each tenant I have to add a plugin which is not good. But suppose I have a registration page (view) common for all but validation and couple of fields are different for each tenant, in that case how can I use same view and controller if validation rules and fields are different (however service can be injected at runtime). - Anupam Singh
You can have custom table that stores the view page Id, tenant id and then the regex. You run the regex when thedata is posted by the particular tenant. - Saravanan

1 Answers

1
votes

I have successfully implemented similar architecture using DI/IoC to inject the correct configuration based on the current logged-in user's tenant. Autofac provides a multi-tenant capability out of the box, I would recommend you check it out.

http://docs.autofac.org/en/latest/advanced/multitenant.html

Sorry for the short answer, writing on mobile is challenging. I will try to edit and expand the answer later when I get to my PC