Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.NHibernate/NHibernateSessionPerActionAttribute.cs @ 67:c8099df941bd
Implementando persistencia con NHibernate en el proyecto web
author | nelopauselli |
---|---|
date | Thu, 19 May 2011 01:24:56 -0300 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
64:240a20cdbcc8 | 67:c8099df941bd |
---|---|
1 using System.Web.Mvc; | |
2 using NHibernate; | |
3 using NHibernate.Context; | |
4 | |
5 namespace Agendas.NHibernate | |
6 { | |
7 public class NHibernateSessionPerActionAttribute : ActionFilterAttribute | |
8 { | |
9 private readonly ISessionFactory _sessionFactory; | |
10 | |
11 public NHibernateSessionPerActionAttribute(ISessionFactory sessionFactory) | |
12 { | |
13 _sessionFactory = sessionFactory; | |
14 } | |
15 | |
16 public override void OnActionExecuting(ActionExecutingContext filterContext) | |
17 { | |
18 var session = _sessionFactory.OpenSession(); | |
19 CurrentSessionContext.Bind(session); | |
20 | |
21 base.OnActionExecuting(filterContext); | |
22 } | |
23 | |
24 public override void OnResultExecuted(ResultExecutedContext filterContext) | |
25 { | |
26 base.OnResultExecuted(filterContext); | |
27 | |
28 var session = _sessionFactory.GetCurrentSession(); | |
29 | |
30 session.Flush(); | |
31 session.Close(); | |
32 | |
33 } | |
34 } | |
35 } |