Clone wiki

Boot.Multitenancy / Home


#NEW# 1.6.4 contains Hierarchy features

Get on Nuget #Multitenancy

Project Boot.MultiTenancy Project sitemap

This project is an extension of nHibernate's ISessionFactory and makes it incredible easy to use multiple sessions within the same application. In BootCms it's used to define different domains and their databases. Read more There are several way of completing configuration, from code, by Host and Tenants or by web.config. Boot.Multitenancy has Fluentnhibernate built in, so no need for extra configuration except setting up databases configuration i web.config. Boot.Multitenancy = By write 1 line of code and add configuration to web.config

If you have suggestions about how to improve this code/project, please contact me.

##When to use Boot.Multitenancy

Currently I use this project in small applications where I want create projects fast complete with a database and a domain. For eg, in internal MVC applications. This makes it easy to use several domains that is easy for customers to remember.

 All in same application but with different domains and  databases. 
 TODO: Separate codebase from domains/databases. Right now all classes that extends the IEntity will be created in each database.

Nuget install version v1.5.9
PM> Install-Package Boot.MultiTenancy

Release notes:
1.6.4 Added hierarchy feature
1.5.8 Added PreInit. Grab configuration before init application.
1.5.5 added AutoPersist property. A boolean to set if to create database.

Init host

In Startup.cs or Application_Start in Global application, add:

//Create reference to Boot.Multitenany.

This will trigger Boot.Multitenancy to look for the configuration in web.config.


Add these lines in web.config (root document) to add a reference to Boot.Multitenancy library. The sessionFactoryConfiguration section is to map the configuration in a separate file.

  <section name="sessionFactoryConfiguration" type="Boot.Multitenancy.Configuration.SessionFactoryConfiguration, Boot.Multitenancy" />  

<sessionFactoryConfiguration configSource="Boot.SessionConfiguration.MySql.config" /><!--Your config file-->

###External config file.

Create a file with a name that suit your database by edit configSource="". For eg. Databases.MySql.config, in the root of application(web project) and add the following content.

<sessionFactoryConfiguration persist="true" namespace="Boot">
      <add name="devdata"
        theme = "Dev"
        connectionstring = "Server=;Port=3306;Database=devdata;Uid=boots;Pwd=boots;"
        properties = "Theme,Dev" />
        <!--Add more databases here if needed.-->

That's all. Now you can start create IEntity items in your database.

##SessionFactoryHostContainer Start using SessionFactoryHostContainer

##Create databases from config before init. Use of ConfigCollection function

#Create Tenant collection from code

It's pretty simple to create a Tenant and add it to Boot.Multitenancy. Create the ITenantConfiguration, and add it to an ITenant. Add each ITenant to the collection. NOTE! See the different databases used in this configuration below.

using Boot.Multitenancy;
using Boot.Multitenancy.Factory;

public static class BootConfig
    public static void Init()
       var conf1 = new TenantConfiguration {
            Key = "MyKeyOne",
            DbType = DbType.MySql5,
            HostValues = new List<string> { "localhost", "" ,"" },
            Properties = new Dictionary<string, object> { {"Theme", "BootSe"} },
            Connectionstring = "Server=;Port=3306;Database=BootTestData;Uid=boots;Pwd=boots;"

        var conf2 = new TenantConfiguration {
            Key = "MyKeyTwo",
            DbType = DbType.SqlCe,
            HostValues = new List<string> { "", "" },
            Properties = new Dictionary<string, object> { { "Theme", "BootCom" } },
            Connectionstring = "Data Source=|DataDirectory|BootData.sdf;Persist Security Info=False;"

            var tenants = new TenantCollection { 
                new Tenant(conf1), 
                new Tenant(conf2)


Whats next?

There are other bennefits from this, for eg. themes that can be read right out of the tenant configuration, if you want.

 var theme = SessionFactoryHostContainer.Current.Theme();

Todo: create a bundle builder for themes.

#Domain administration

I created a project in MVC to add/edit domains etc. See

#Future# In the future I will add support to separate codebase from domains. Currently all IEntity's will be created in all databases. To separate these I will probably add a property on the class with an ID or separating namespaces.