首页 > 解决方案 > Hangfire + SimpleInjector + MVC

问题描述

我正在尝试为我们的 MVC 应用程序设置 Hangfire。我遵循了所有教程,使用 Devmondo HangFire.SimpleInjector 进行激活逻辑,但仍然存在问题。

我的启动设置如下:

//Hangfire
Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage(webClientConfigurationService.DataConnectionStringName);
Hangfire.GlobalConfiguration.Configuration.UseActivator(new SimpleInjectorJobActivator(Core.Dependencies.DependencyResolver.Container));
app.UseHangfireDashboard();
app.UseHangfireServer();

        //add hangfire test job
        var _selfAccreditationsService = Core.Dependencies.DependencyResolver.Resolve<ISelfAccreditationsService>();
        RecurringJob.AddOrUpdate(() => _selfAccreditationsService.TestHangFire(), Cron.MinuteInterval(1));

应用程序启动正常,但是当我去仪表板时,我可以看到:

System.TypeLoadException: Could not load type ‘SimpleInjector.Lifestyles.AsyncScopedLifestyle’ from assembly ‘SimpleInjector, Version=3.1.2.0, Culture=neutral, PublicKeyToken=984cb50dea722e99’.
at Hangfire.SimpleInjector.SimpleInjectorJobActivator.BeginScope(JobActivatorContext context)
at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context)
at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass8_0.b__0()
at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func1 continuation) at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext context, IEnumerable1 filters)
at Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext context)
at Hangfire.Server.Worker.PerformJob(BackgroundProcessContext context, IStorageConnection connection, String jobId)

编辑:即使在添加以上所有内容后使用新的 MVC 模板项目,它仍然给我同样的错误:皱眉:

你们有什么想法我错过了吗?非常感谢您对此的任何帮助。

谢谢

标签: c#hangfire

解决方案


推荐阅读