简体   繁体   English

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

[英]Hangfire disposes of autofac dependencies which are defined as SingleInstance

Using hangfire 1.3.4 with hangfire.autofac 1.0.0 in an ASP.NET application. 在ASP.NET应用程序中将hangfire 1.3.4与hangfire.autofac 1.0.0一起使用。 I have the following scenario: 我有以下情况:

 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();

What I see is that Autofac executes the recurrent job as requested but then disposes of instance of MyType, which obviously causes failures on subsequent calls for it, since it's defined as a singleton, and should be disposed of by Autofac upon shutdown. 我看到的是Autofac根据请求执行了周期性作业,但随后处理了MyType实例,这显然会导致后续调用失败,因为它被定义为单例,应该在关机时由Autofac处置。

Am I missing something or is this a bug? 我是否缺少某些东西或这是一个错误?

Here's the callstack: 这是调用栈:

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.JobPerform MyDll.dll!MyType.Dispose()第316行C#Hangfire.Core.dll!Hangfire.Common.Job.Dispose(对象实例)未知Hangfire.Core.dll!Hangfire.Common.Job.Perform(Hangfire.JobActivator激活器,Hangfire .IJobCancellationToken cancellingToken)未知的Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.PerformJobWithFilters.AnonymousMethod__6()未知的Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.InvokePerformFilter(Hangfire.Server.IServerFilter过滤器,Hangfire.Server.Performing ,System.Func延续)未知Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.PerformJobWithFilters.AnonymousMethod__8()未知Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.InvokePerformFilter(Hangfire.Server.IServerFilter过滤器,Hangfire.Server。 PerformingContext preContext,System.Func延续)未知Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.PerformJobWithFilters.AnonymousMethod__8()未知Hangfire.Core.dll!Hangfire.Server.JobPerform anceProcess.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.ServerSuperviso anceProcess.PerformJobWithFilters(Hangfire.Server.PerformContext上下文,Hangfire.Server.IJobPerformer执行者,System.Collections.Generic.IEnumerable筛选器)未知Hangfire.Core.dll!Hangfire.Server.JobPerformanceProcess.Run(Hangfire.Server.PerformContext上下文,Hangfire .Server.IJobPerformer执行者)未知Hangfire.Core.dll!Hangfire.Server.Worker.ProcessJob(字符串jobId,Hangfire.Storage.IStorageConnection连接,Hangfire.Server.IJobPerformanceProcess进程,System.Threading.CancellationToken shutdownToken)未知Hangfire.Core。 dll!Hangfire.Server.Worker.Execute(System.Threading.CancellationToken cancelleToken)未知Hangfire.Core.dll!Hangfire.Server.AutomaticRetryServerComponentWrapper.ExecuteWithAutomaticRetry(System.Threading.CancellationToken cancellingToken)未知Hangfire.Core.dll!Hangfire.Server。 AutomaticRetryServerComponentWrapper.Execute(System.Threading.CancellationToken cancelledToken)未知Hangfire.Core.dll!Hangfire.Server.ServerSuperviso r.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] r.ExecuteComponent()未知Hangfire.Core.dll!Hangfire.Server.ServerSupervisor.RunComponent()未知mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(对象状态)未知mscorlib.dll!System.Threading.ExecutionContext.RunInternal( System.Threading.ExecutionContext执行上下文,System.Threading.ContextCallback回调,对象状态,布尔类型saveSyncCtx)未知mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext执行上下文,System.Threading.ContextCallback回调,对象状态, bool prepareSyncCtx)未知mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executeContext,System.Threading.ContextCallback回调,对象状态)未知mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()未知[本地到托管过渡]

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

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

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