简体   繁体   English

使用Autofac在WebApi中进行Hangfire:作业未运行

[英]Hangfire in WebApi with Autofac: Job not running

I use Hangfire with the Hangfire.MemoryStorage in my WebApi Application. 我用迟发型与Hangfire.MemoryStorage在我的WebAPI的应用。

I configured Hangfire in my owin startup.cs : 我在owin startup.cs配置了Hangfire:

 Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage();
 app.UseHangfireServer();

And I try to use the job activation in a controller 我尝试在控制器中使用作业激活

var jobId = BackgroundJob.Schedule(
                    () => ForceMissionEmail(mission.Guid),
                    TimeSpan.FromSeconds(10));

The code runs without error but the ForceMissionEmail method is not called after 10 seconds. 该代码运行无误,但10秒钟后未调用ForceMissionEmail方法。

Using the Hangfire.Autofac Nuget package and the following lines of code resolves my problem 使用Hangfire.Autofac Nuget软件包和以下代码行可以解决我的问题

IContainer container = AutoFacConfig.Register(config, app);
Hangfire.GlobalConfiguration.Configuration.UseAutofacActivator(container);
Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage();
app.UseHangfireServer();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM