В Spring.NET за инстанцирование сессии NHibernate отвечает класс LocalSessionFactoryObject
. Чтобы загрузить меппинг Fluent из сборок нужно унаследоваться от LocalSessionFactoryObject
и перекрыть методы. создающие сессию.
Так:
public class FluentNhibernateLocalSessionFactoryObject
: LocalSessionFactoryObject
{
protected override void PostProcessConfiguration(Configuration config)
{
base.PostProcessConfiguration(config);
Fluently.Configure(config)
.Database(MySQLConfiguration.Standard.ConnectionString(
c => c.FromConnectionStringWithKey("connectionString")))
.Mappings( m => m
.FluentMappings
.AddFromAssemblyOf<FluentNHibernateLocalSessionFactoryObject>())
.BuildSessionFactory();
}
}
Или так:
public class FluentNhibernateLocalSessionFactoryObject
: LocalSessionFactoryObject
{
protected override ISessionFactory NewSessionFactory(Configuration config)
{
config = Fluently.Configure(config)
.Mappings(m => m
.FluentMappings
.AddFromAssemblyOf<FluentSessionFactoryObject>())
.BuildConfiguration();
return base.NewSessionFactory(config);
}
}