Wiki

Clone wiki

Boot.Multitenancy / Configuration

multitenancy.png

#Multitenancy configuration

Boot.Multitenancy configuration has it's setup in web.config. You can assign multiple domains to connect to a database. To add a database and domains, see configuration below.

##QuickGuide

Below is a quick and easy description of how to setup multipe domains and databases in a few minits.

###Web.config

Edit and add the sessionFactoryConfiguration to configSections like below.

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

###SessionFactoryConfiguration

Create the sessionFactoryConfiguration.

<sessionFactoryConfiguration persist="true" namespace="Boot"> <!--namespace for your IEntity's -->
<databases>
  <clear/>

  <add name="boot"  <!--Name of database-->
       autoPersist="true" <!--Should it be updatable? -->
       dbType="SqlCe"  <!-- Which type of database to use. -->
       domains="localhost|www.boot.se|boot.se" /> <!-- Your domains associated with this database. -->

  <add name="devdata" 
       autoPersist="true" 
       dbType="SqlCe" 
       domains="dev.boot.com|tech.boot.com|www.boot.com|boot.com" />

  <add name="netdata" 
       autoPersist="true" 
       dbType="SqlCe" 
       domains="www.boot.net|boot.net" />

   <!-- All databases here, gets automatically created-->

</databases>
</sessionFactoryConfiguration>

##Create databases

The Host.PreInit reads out connectionstring from web.config and return these as a list for creation of databases. In this way there no doubt that values a correct.

#!c#
            (from tenant in Host.TenantCollection select tenant)
              .ToList()
                  .ForEach(d => {
                      try
                      {
                            if(!d.Exist())
                            new SqlCeEngine(d.Configuration.Connectionstring).CreateDatabase();
                        }
                      catch { }
                  });


            Host.Init();

#Setup your Models/Repositories.

Next -->> Continue read here for more information on how to setup your repository to retrieve data..

#Options * SessionFactoryConfiguration with persist set to true inits the configuration. * Add section Name of the key for this connection, nust be unique. AutoPersist set to true, creates the database and scripts. DbType, wish type of database to use. (Currently only SqlCe) Domains, A separated list of domain(Host header values) delimiter "|" ** Namespace, The namespace where to find your Enity's

##Initialization

Boot.Multitenancy automatically inits the configuration if the persist is set to true.

Call Host.Init() in application_start of global.cs. when you have added configuration.

Updated