forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppSessionFactory.cs
40 lines (34 loc) · 1.16 KB
/
AppSessionFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Example.Web.Models;
using NHibernate.Mapping.ByCode;
namespace NHibernate.Example.Web.Infrastructure
{
public class AppSessionFactory
{
public Configuration Configuration { get; }
public ISessionFactory SessionFactory { get; }
public AppSessionFactory(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory)
{
NHibernate.NHibernateLogger.SetLoggersFactory(new NHibernateToMicrosoftLoggerFactory(loggerFactory));
var mapper = new ModelMapper();
mapper.AddMapping<ItemMap>();
var domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
Configuration = new Configuration();
Configuration.DataBaseIntegration(db =>
{
db.ConnectionString = @"Server=(local)\SQLEXPRESS;initial catalog=nhibernate;Integrated Security=true";
db.Dialect<MsSql2008Dialect>();
db.Driver<Sql2008ClientDriver>();
})
.AddMapping(domainMapping);
Configuration.SessionFactory().GenerateStatistics();
SessionFactory = Configuration.BuildSessionFactory();
}
public ISession OpenSession()
{
return SessionFactory.OpenSession();
}
}
}