城堡活动记录中的会话管理 [英] Session Management in Castle Active Record
问题描述
如果我通过nHibernate使用Castle Active Record,如何管理会话.如果直接使用nHibernate,基本上可以自行管理ISession的生命周期.但是,当我使用Castle AR时,它无法为我提供管理会话生命周期的方法.我想每个线程使用一个会话.
How do I manage session if I am using Castle Active Record over nHibernate. Basically I can manage the life cycle of ISession on my own if I am using nHibernate directly. But when I am using Castle AR it does not give me a way to manage the life cycle of the session. I want to use single Session per thread.
我正在WCF服务中使用Castle AR,并且想针对每个WCF请求使用会话.
推荐答案
而不是使用ISession,而是要在Castle ActiveRecord中使用SessionScope:
Instead of using ISession, in Castle ActiveRecord you want SessionScope:
using(new SessionScope())
{
; // do work here
}
如果由于某种原因需要访问SessionScope内部的ISession,可以执行以下操作:
If you need access to the ISession inside the SessionScope for some reason, you can do this:
ISession dbSession = Castle.ActiveRecord.ActiveRecordMediator
.GetSessionFactoryHolder().CreateSession(
typeof(Castle.ActiveRecord.ActiveRecordBase));
更多文档在这里:
http://www.castleproject.org/activerecord /documentation/trunk/usersguide/scopes.html#sess_scope
在这里:
http://www.castleproject.org/activerecord/documentation /trunk/manual/scopes.html
这篇关于城堡活动记录中的会话管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!