这个 ISession 是由 SessionScope 处理的吗 - Castle ActiveRecord
我可以这样做吗?
我的代码中有以下内容:
public class ARClass : ActiveRecordBase<ARClass>
{
---SNIP---
public void DoStuff()
{
using (new SessionScope())
{
holder.CreateSession(typeof(ARClass)).Lock(this, LockMode.None);
...Do some work...
}
}
}
因此,正如我确信您可以猜到的那样,我这样做是为了可以访问对象中的延迟加载引用。它工作得很好,但是我担心创建这样的 ISession 并删除它。它是否在 SessionScope 中正确注册,并且在处理它时,范围是否会正确地减少我的 ISession 的皮重?或者我需要自己做更多的事情来管理它吗?
Can I do this?
I have the following in my code:
public class ARClass : ActiveRecordBase<ARClass>
{
---SNIP---
public void DoStuff()
{
using (new SessionScope())
{
holder.CreateSession(typeof(ARClass)).Lock(this, LockMode.None);
...Do some work...
}
}
}
So, as I'm sure you can guess, I am doing this so that I can access lazy loaded references in the object. It works great, however I am worried about creating an ISession like this and just dropping it. Does it get properly registered with the SessionScope and will the scope properly tare my ISession down when it is disposed of? Or do I need to do more to manage it myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,是的,这很好用。我没有发现这个方法有任何问题。
我有一个抽象基类
我所有的 AR 类都继承自。在这个类中,我定义了一个 Reattach
功能。
只要你小心,这个方法就很好用。如果你这样做,它将不起作用
位于活动 SessionScope 之外,或者该对象已经存在
附加到活动的 ISession。
它看起来是这样的:
As far as I can tell, yes this works fine. I have found no issues with this method.
I have an abstract base class that
all of my AR classes inherit from. In this class, I define a Reattach
function.
This works fine, as long as you are careful. It will not work if you
are outside an active SessionScope or if the object is already
attached to an active ISession.
This is what it looks like: