[英]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()第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上下文,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()未知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.