Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using CumbriaMD.Web.Controllers;
- using NHibernate;
- using NHibernate.Cfg;
- namespace CumbriaMD.Web.Filters
- {
- public class NHibernateActionFilter : ActionFilterAttribute
- {
- private static readonly ISessionFactory sessionFactory = BuildSessionFactory();
- private static ISessionFactory BuildSessionFactory()
- {
- return new Configuration()
- .Configure()
- .BuildSessionFactory();
- }
- public override void OnActionExecuting(ActionExecutingContext filterContext)
- {
- var sessionController = filterContext.Controller as SessionController;
- if (sessionController == null)
- return;
- sessionController.Session = sessionFactory.OpenSession();
- }
- public override void OnActionExecuted(ActionExecutedContext filterContext)
- {
- var sessionController = filterContext.Controller as SessionController;
- if (sessionController == null)
- return;
- var session = sessionController.Session;
- if (session == null)
- return;
- session.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment