我试图让Quartz.net(2.1.2)使用IoC容器(autofac),因为我需要在预定的作业中使用服务.我在这个主题上找到了类似的帖子,但我似乎找不到一个具有autofac特定注册示例的帖子.
以下帖子涉及我遇到的同一问题:
但是,我相信我缺少的那部分是答案说"并且不要忘记在IoC容器中注册作业".我不确定如何准确地做到这一点,因为到目前为止我所尝试的一切都没有奏效.
在下面的示例中,"HelloJob"将运行,但每当我尝试将releaseService注入"ReleaseJob"时,它都拒绝运行.
更新: 我在DependencyRegistration.cs部分标记了我认为问题所在的代码.
更新2: 一些与我需要做的相关的链接可能有所帮助(我已经完成了所有这些但仍然无法弄清楚如何使用autofac):
如何以PRO方式使用Quartz.NET? - http://blog.goyello.com/2009/09/21/how-to-use-quartz-net-in-pro-way/
Autofac和Quartz.NET - http://blog.humann.info/post/2013/01/30/Autofac-and-QuartzNET.aspx
使用Quartz.NET和Simple Injector进行构造函数注入 - 使用Quartz.NET和Simple Injector进行构造函数注入
ASP.Net MVC 3,Ninject和Quartz.Net - 如何? - ASP.Net MVC 3,Ninject和Quartz.Net - 如何?
这是相关代码:
Global.asax中
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
var dependencyRegistration = new DependencyRegistration();
dependencyRegistration.Register();
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(new ValidatorFactory()));
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
}
Run Code Online (Sandbox Code Playgroud)
DependencyRegistration.cs
public class DependencyRegistration
{
public void Register()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterAssemblyModules(Assembly.GetExecutingAssembly());
// Validation
builder.RegisterType<ValidatorFactory>()
.As<IValidatorFactory>()
.InstancePerHttpRequest();
AssemblyScanner findValidatorsInAssembly …Run Code Online (Sandbox Code Playgroud)