我有一个asp.net过程,也消耗来自服务总线(MassTransit)的消息。对于webrequests,我的数据库会话使用PerWebRequest生活方式解决。温莎复合生活方式的asp.net过程
但是当进程消耗来自MassTransit的消息时,我需要数据库会话拥有另一种生活方式,因为没有HttpContext可用。
我有此:
public class PerRequestLifeStyleManager : ILifestyleManager
{
readonly PerWebRequestLifestyleManager perWebRequestLifestyleManager;
readonly PerThreadLifestyleManager perThreadLifestyleManager;
public PerRequestLifeStyleManager()
{
perWebRequestLifestyleManager = new PerWebRequestLifestyleManager();
perThreadLifestyleManager = new PerThreadLifestyleManager();
}
public void Init(IComponentActivator componentActivator, IKernel kernel, ComponentModel model)
{
perWebRequestLifestyleManager.Init(componentActivator, kernel, model);
perThreadLifestyleManager.Init(componentActivator, kernel, model);
}
public object Resolve(CreationContext context)
{
return GetManager().Resolve(context);
}
public bool Release(object instance)
{
return GetManager().Release(instance);
}
public void Dispose()
{
GetManager().Dispose();
}
ILifestyleManager GetManager()
{
if (HttpContext.Current != null)
{
return perWebRequestLifestyleManager;
}
return perThreadLifestyleManager;
}
}
谁能告诉我,如果这是正确的方式去?如果不是,那是什么?
谢谢。
编辑:我刚刚更新了一些代码似乎工作(未经测试之前)的问题。我仍然渴望知道,从温莎的角度来看,这是否安然无恙。
一个好地方,检查,将是MassTransit邮件列表。 http://groups.google.com/group/masstransit-discuss我认为德鲁有足够的经验与城堡,他可以引导你在正确的方向,但我当然不会。我没有碰它;) – Travis
我一直在那里,但只能通过它搜索。我认为这是一个温莎和MassTransit之间的相互关系有点太过分了:) ......但是,谢谢你的提示,我会在那里发布它! – asgerhallas
这里有一些关于会话管理的讨论:http://groups.google.com/group/masstransit-discuss/browse_thread/thread/4be42a6319ce66ff/6f28a2eeea52278a?lnk=gst&q=windsor+lifestyle#6f28a2eeea52278a ...我什么都没有“不知道你是如何做出自定义的生活方式的,那是基于这两个回调之前/之后的...... – asgerhallas