main
1using momoney.database.transactions;
2using momoney.service.infrastructure.transactions;
3
4namespace MoMoney.Service.Infrastructure.Transactions
5{
6 public class UnitOfWork : IUnitOfWork
7 {
8 readonly ISession session;
9 readonly IContext context;
10 readonly IKey<ISession> key;
11
12 public UnitOfWork(ISession session, IContext context, IKey<ISession> key)
13 {
14 this.session = session;
15 this.context = context;
16 this.key = key;
17 }
18
19 public void commit()
20 {
21 if (is_dirty()) session.flush();
22 }
23
24 public bool is_dirty()
25 {
26 return session.is_dirty();
27 }
28
29 public void Dispose()
30 {
31 context.remove(key);
32 session.Dispose();
33 }
34 }
35}