Wiki

Clone wiki

Boot.Multitenancy / SessionFactoryHostContainer

sessionfactoryhostcontainer.png

#SessionFactoryHostContainer

This is a container that queries ISessions from each associated domain. When you acquired your ISession, you just use it like an ordinary Nhibernate ISession.

##How to use SessionFactoryHostContainer

When creating a new for e.g ViewModel or Model and want to connect to an ISession, or really a database object, you just add two lines of code.

###Example Study the code below. This is all i take to connect to several databases. Even though you have 10 databases and hundreds of domains associated it still connects to the correct database.

Note! You can use all regular nHibernate querys you're use to or the built in extras.

#!c#

    public class PageViewModel
    {
        ISession session { get; set; } //ISession

        public PageViewModel()
        {
            session = SessionFactoryHostContainer.CurrentFactory.OpenSession(); //Assaign session
        }
        public List<Page> Pages{ get{ return session.All<Page>();} }
    }

##Transactions made easy Continue read about the transaction extension.

Updated