179
|
1 using System;
|
|
2 using NHibernate;
|
|
3 using NHibernate.Context;
|
|
4
|
|
5 namespace Agendas.NHibernate
|
|
6 {
|
|
7 public class SessionScope : IDisposable
|
|
8 {
|
|
9 private readonly ISessionFactory _sessionFactory;
|
|
10
|
|
11 public SessionScope(ISessionFactory sessionFactory)
|
|
12 {
|
|
13 _sessionFactory = sessionFactory;
|
|
14
|
|
15 var session = _sessionFactory.OpenSession();
|
|
16 CurrentSessionContext.Bind(session);
|
|
17 }
|
|
18
|
|
19 public void Dispose()
|
|
20 {
|
|
21 var session = _sessionFactory.GetCurrentSession();
|
|
22
|
|
23 session.Flush();
|
|
24 session.Close();
|
|
25 }
|
|
26 }
|
|
27 } |