问题描述
我有ASP.NET MVC 3.0应用程序,使用EF code首先进行数据层。我已实施的工作格局的单位,我在HttpContext.Current.Items [SomeKey]集合结合工作单元的上下文。工作单位创建并致力在控制器OnActionExecuting /执行的事件。我用实例温莎城堡库。
I have ASP.NET MVC 3.0 application, with EF Code First for data layer. I have implemented a Unit of work pattern, I’m binding context of the unit of work on HttpContext.Current.Items[SomeKey] collection. Unit of work is created and committed in OnActionExecuting/Executed events on controller. I’m instantiating repositories using Windsor Castle.
现在我需要使用Quartz.net在我的应用程序定期运行工作,这项工作还需要使用一些仓库。的问题是,在一个SchedulerJob实施方式中,没有可用的(确实)HttpContext的。我怎样才能实例从Quartz.net工作在这种情况下的存储库(这需要UnitOfWorkFactory作为构造参数)?我怎么能代替缺失的HttpContext?我可能需要实现另一个UnitOfWorkFactory,但我不知道在那里我可以结合我的情况下,如何只是Quartz.net线程注册不同的工厂。可以请你告诉我一个方法或模式?谢谢你。
Now I need to use Quartz.net to run a job periodically in my app, this job need also use few repositories. The problem is, that in a SchedulerJob implementation, there is no HttpContext available (indeed). How can I instantiate a repository (which takes UnitOfWorkFactory as constructor parameter) from a Quartz.net Job in that case? How can I substitute missing HttpContext? I will probably need to implement another UnitOfWorkFactory, but I’m not sure where I can bind my context and how to register different factory just for Quartz.net thread. Can you please show me a way or pattern? Thank you.
推荐答案
工作落实的单位属于业务逻辑层,不应该依赖于特定的presentation层,如MVC上。
The unit of work implementation belongs to the business logic layer and should not depend on a specific presentation layer such as MVC.
我做了一个自定义的UnitOfWorkScope,我已经在几个项目中使用:的
I made a custom UnitOfWorkScope that I've used in a couple of projects: http://coding.abel.nu/2012/10/make-the-dbcontext-ambient-with-unitofworkscope/
这篇关于如何首先实施EF code在ASP.NET MVC与UnitOfWorkPattern一个Quartz.NET工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!