I have been stepping through the source code for Orchard CMS to learn how they have tackled Multi-tenancy.
OrchardProject
Can someone point out the files or areas I should be looking at to understand how the plumbing works for Multi-tenancy in Orchard?
- How and where is the domain name deciphered to get the tenant from the DB?
- How is the tenant configuration details maintained throughout the time the user is on the site - sessions?
As a test project, I want to be able to write similar bare-bone code in an ASP.Net MVC application to demonstrate multi-tenancy.
The areas I have looked at:
- OnBeginRequest
- Global.cs
- Stater.cs
You need to install the multi-tennancy module from the orchard gallery, enable it, and configure it in settings.
The code you want to look at is, the code that is in the multi-tennant module subfolder.
However, knowing how Orchard does multi-tenancy won't much help you. Orchard has a very complex routing and extension system, with tons of layers and dynamic dispatch points. You can't simply drop in Orchard's internal system into a simple MVC app without, basically, recreating all of Orchard's infrastructure.
Orchard is not a good example of how to write a stand-alone MVC app, because it has so many requirements for flexibility, and its system is so heavly based on the dynamic claysharp stuff.
Unless there is a reason you need to use the Orchard method specifically, you'd be better suited looking at solutions like this http://weblogs.asp.net/zowens/archive/tags/Multi-tenancy/default.aspx
Perhaps this will help you. I implemented a complete MVC multi-tennant app. Here are some links I found handy and some sample apps:
http://msdn.microsoft.com/en-us/library/aa479086.aspx
http://weblogs.asp.net/zowens/multi-tenant-asp-net-mvc-introduction
http://lonetechie.com/2012/09/25/multi-tenant-architecture-with-asp-net-mvc-4/
http://codeofrob.com/archive/2010/02/14/multi-tenancy-in-asp.net-mvc-controller-actions-part-i.aspx
http://mvcex.codeplex.com/
http://www.developer.com/design/article.php/10925_3801931_2/Introduction-to-Multi-Tenant-Architecture.htm
http://msdn.microsoft.com/en-us/library/aa479086.aspx#mlttntda_cc
http://lukesampson.com/post/303245177/subdomains-for-a-single-application-with-asp-net-mvc
http://code.google.com/p/multimvc/
http://www.agileatwork.com/bolt-on-multi-tenancy-in-asp-net-mvc-with-unity-and-nhibernate/
http://ayende.com/blog/3530/multi-tenancy-approaches-and-applicability
http://weblogs.asp.net/zowens/archive/tags/Multi-tenancy/default.aspx
http://cloudsamurai.codeplex.com/
http://cloudninja.codeplex.com/
http://msdn.microsoft.com/en-us/library/hh534484.aspx
Even starting from scratch, you are in for a world of hurt. The MVC framework does very little to help you address the issues.
There are some sample projects demonstrating multi-tenant deployments:
Cloud Ninja
Cloud Samurai