Home

Castle Stronghold

NHibernate Facility

The NHibernate Facility enables the usage of NHibernate O/R framework for your components.

Facility Summary
Uses ProxyNo
Requires configurationYes
Uses attributeNo
VersionBeta 3
Maturity levelMedium

Introduction

The NHibernate facility provides two levels of integration with NHibernate. You should pick the one you feel more comfortable with.

Integration level 1

This example illustrates how you can have fine grained control over ISessionFactory and, thus, ISession.


using NHibernate;
using NHibernate.Cfg;

public class MyDataAccessClass
{
    private ISessionFactory _sessFactory;
    private Configuration _cfg;

    public MyDataAccessClass(ISessionFactory sessFactory, Configuration cfg)
    {
        _sessFactory = sessFactory;
        _cfg = cfg;
    }

    public void SaveSomething(object item)
    {
        ISession session = _sessFactory.OpenSession();

        // .. do whatever you want 

        session.Close();
    }
}

With this scenario you have to control transactions and share sessions instances manually.

Integration level 2

The second level of integration introduce the ISessionManager interface so you can use session and leave to the ISessionManager implementation the responsability of sharing compatible session within an invocation chain and be aware of transactions.

Site Map

Please consult the others documents to learn more about the NHibernate facility.

Required Assemblies

Google
Search WWW Search castleproject.org