Quartz.net + NHibernate + 温莎城堡 + 公共服务定位器
我有一个基于 sharp-architecture 框架的网络应用程序。 它实际上使用 NHibernate 作为 dal,并且我在(VIEW-CONTROLLER)和 DAL 之间添加了一个服务层。
我实际上需要实现一个调度程序来频繁运行我的作业。 我将使用 Quartz.net 来完成该任务。 实际上我面临着一个问题。 因为我会有很多工作按照不同的时间表运行,比如每 30 秒、每天、每周。
我想知道是否有一种方法可以在 Quartz 内通过服务注入来运行 NHibernate ,以及它是否支持作业并发,我的意思是如果两个作业同时运行,如果有使用 NHibernate 不会有任何问题。 我知道 NHibernate 和多线程存在一些问题。
我找到了 Spring 的 Quartz.Net 实现(http://www.zorched.net/2009/03/07/using-quartznet-springnet-and-nhibernate-to-run-scheduled-tasks-in-aspnet/ )和 Castle-Windsor 的实现(http ://bugsquash.blogspot.com/2009/03/windsor-facility-for-quartznet.html)。
问题是,我认为这个例子没有考虑到作业可以同时运行的情况,这是一个 Nhibernate 问题。 我想使用 CommonServiceLocator 达到更高的水平,而不是将自己限制在一个 IoC 框架上。
解决此问题的最佳方法是什么?
感谢您的帮助
I have a web application based on the sharp-architecture framework. It actually use NHibernate for the dal, and i've added a service layer between the (VIEW-CONTROLLER) and the DAL.
I actually need to implement a scheduler to run my jobs frequently. I will use Quartz.net to do that task. Actually i'm facing a problem. Because I will have lot's of jobs that will run at different schedule, like every 30 sec, every days, every weeks.
I want to know if there is a way to run NHibernate with service injection inside Quartz, and if it will support job concurrence, I mean if two jobs runs simultaniously, if there will be no problems with NHibernate. I know there is some issue with NHibernate and multithreading.
I found an implementation of Quartz.Net for Spring (http://www.zorched.net/2009/03/07/using-quartznet-springnet-and-nhibernate-to-run-scheduled-tasks-in-aspnet/) and an implementation for Castle-Windsor (http://bugsquash.blogspot.com/2009/03/windsor-facility-for-quartznet.html).
The problem is, I think this examples don't take care of the case that jobs can be ran simultaniously, that's an Nhibernate problem. And i want to use CommonServiceLocator to be more high level and not limit myself to one IoC framework.
What can be the best approach to solve this problem ?
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 NHibernate 工具,然后注入
ISessionManager< /code> 在您的
IJob
中。 这应该为每个线程提供一个 ISession,并且应该不会有任何问题。Use the NHibernate facility, then inject
ISessionManager
in yourIJob
s. That should give you one ISession per thread and you should have no problems.请参阅此 http://docs.castleproject.org/Contrib.Quartz-Net-integration .ashx
See this http://docs.castleproject.org/Contrib.Quartz-Net-integration.ashx