Created
November 15, 2012 09:58
-
-
Save DominicFinn/4077768 to your computer and use it in GitHub Desktop.
SessionBuilder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using FluentNHibernate.Cfg; | |
| using FluentNHibernate.Cfg.Db; | |
| using NHibernate; | |
| using NHibernate.Tool.hbm2ddl; | |
| using TeaLeague.Core.Domain; | |
| namespace TeaLeague.Core.Database | |
| { | |
| public interface INHibernateHelper | |
| { | |
| ISession OpenSession(); | |
| } | |
| public class NHibernateHelper : INHibernateHelper | |
| { | |
| private static ISessionFactory sessionFactory; | |
| private static ISessionFactory SessionFactory | |
| { | |
| get | |
| { | |
| if (sessionFactory == null) | |
| InitializeSessionFactory(); | |
| return sessionFactory; | |
| } | |
| } | |
| private static void InitializeSessionFactory() | |
| { | |
| sessionFactory = Fluently.Configure() | |
| .Database(MsSqlConfiguration.MsSql2008 | |
| .ConnectionString( | |
| @"Server=localhost;Database=TeaLeague;Integrated Security=SSPI;") | |
| .ShowSql() | |
| ) | |
| .Mappings(m => | |
| m.FluentMappings | |
| .AddFromAssemblyOf<User>()) | |
| .ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true)) | |
| .BuildSessionFactory(); | |
| } | |
| public ISession OpenSession() | |
| { | |
| return SessionFactory.OpenSession(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment