c# - Hangfire、EF dbContext 和 JSON 参考循环
问题描述
我想使用 Hangfire 从我的 ASP.net Core API 运行具有数据库操作的后台任务。
我安装了 Hangfire nuget 并将 SQL dbConnection 设置在Startup.cs
:
GlobalConfiguration.Configuration.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"));
当我现在想开始一项后台工作时:
var jobId = BackgroundJob.Enqueue(() => RebuildVersionHistoryCacheAsync(statisticContext));
我收到如下错误:
JsonSerializationException: Self referencing loop detected for property 'Context' ...
我都尝试了,将全局序列化程序设置设置为忽略循环并设置hangfire设置做同样的事情:
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
...
services.AddHangfire((sp, config) =>
{
config.UseSerializerSettings(new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
});
没有效果。
Hangfire 的配置有什么我想念的吗?或者,Hangfire 在 BackgroundJobs 中结合 EF Core 数据库上下文是否存在基本问题?
解决方案
推荐阅读
- java - 整数值不递增
- javascript - D3.js / 如何使用 JSON 文件中的数据数组绘制多系列图?
- php - NuSOAP - HTTP 错误:HTTP 标头后不存在数据
- terminal - 终端命令以获取以特定模式结尾的隐藏文件
- python - IndexError:列表索引超出范围以制作可变结构库
- postgresql - 对等点重置连接/过多 Postgres 连接导致管道损坏
- splunk - 如何在 Splunk 中解析 JSON 指标数组
- apache - 如何在 apache http 服务器中强制更改密码策略?
- jquery - 触发jquery单击基于数组的数据属性的元素
- heroku - 如何使用 JHipster 在 Heroku 中调试响应:“您的请求无法处理”的应用程序?