Hangfire 处理定义为 SingleInstance 的 autofac 依赖项

Hangfire disposes of autofac dependencies which are defined as SingleInstance

在 ASP.NET 应用程序中使用 hangfire 1.3.4 和 hangfire.autofac 1.0.0。 我有以下情况:

 class MyType : IDisposable 
 {
      public void Start()
      {
          RecurringJob.AddOrUpdate("background-update", () => ProcessData(), Cron.Daily());
          RecurringJob.Trigger("background-update"); 
      }

     public void ProcessData(){...}

     public void Dispose(){...} 
 }
 ...
 var builder = new ContainerBuilder();
 builder.RegisterType<MyType>().SingleInstance();
 var cont = builder.Build();
 app.UseHangfire(config =>
        {
            var options = new SqlServerStorageOptions();
            config.UseAutofacActivator(cont);
            config.UseSqlServerStorage("MyServer", options);
            config.UseServer();
        });

...
var c = cont.Resolve<MyType>();
c.Start();

我看到的是 Autofac 按要求执行循环作业,然后处理 MyType 的实例,这显然会导致后续调用失败,因为它被定义为单例,并且应该由 Autofac 处理关机。

我是不是遗漏了什么或者这是一个错误?

这是调用堆栈:

MyDll.dll!MyType.Dispose() Line 316 C# Hangfire.Core.dll!Hangfire.Common.Job.Dispose(object instance) Unknown Hangfire.Core.dll!Hangfire.Common.Job.Perform(Hangfire.JobActivator activator, Hangfire.IJobCancellationToken cancellationToken) Unknown Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.PerformJobWithFilters.AnonymousMethod__6() Unknown Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.InvokePerformFilter(Hangfire.Server.IServerFilter filter, Hangfire.Server.PerformingContext preContext, System.Func continuation) Unknown Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.PerformJobWithFilters.AnonymousMethod__8() Unknown Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.InvokePerformFilter(Hangfire.Server.IServerFilter filter, Hangfire.Server.PerformingContext preContext, System.Func continuation) Unknown Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.PerformJobWithFilters.AnonymousMethod__8() Unknown Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.PerformJobWithFilters(Hangfire.Server.PerformContext context, Hangfire.Server.IJobPerformer performer, System.Collections.Generic.IEnumerable filters) Unknown Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.Run(Hangfire.Server.PerformContext context, Hangfire.Server.IJobPerformer performer) Unknown Hangfire.Core.dll!Hangfire.Server.Worker.ProcessJob(string jobId, Hangfire.Storage.IStorageConnection connection, Hangfire.Server.IJobPerformanceProcess process, System.Threading.CancellationToken shutdownToken) Unknown Hangfire.Core.dll!Hangfire.Server.Worker.Execute(System.Threading.CancellationToken cancellationToken) Unknown Hangfire.Core.dll!Hangfire.Server.AutomaticRetryServerComponentWrapper.ExecuteWithAutomaticRetry(System.Threading.CancellationToken cancellationToken) Unknown Hangfire.Core.dll!Hangfire.Server.AutomaticRetryServerComponentWrapper.Execute(System.Threading.CancellationToken cancellationToken) Unknown Hangfire.Core.dll!Hangfire.Server.ServerSupervisor.ExecuteComponent() Unknown Hangfire.Core.dll!Hangfire.Server.ServerSupervisor.RunComponent() Unknown mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Unknown mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Unknown [Native to Managed Transition]

这在 hangfire 的最新(测试版)版本中已修复,有关详细信息,请参阅 https://github.com/HangfireIO/Hangfire/issues/329