Hangfire Autofac .net 核心 3.1 [英] Hangfire Autofac .net core 3.1

查看:40
本文介绍了Hangfire Autofac .net 核心 3.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Hangfire.Autofac 并尝试根据文档对其进行配置:

I am using Hangfire.Autofac and trying to configure it based on the documentation:

GlobalConfiguration.Configuration.UseAutofacActivator(builder.Build());

但我得到以下异常:

Build() 或 Update() 只能在 ContainerBuilder 上调用一次

Build() or Update() can only be called once on a ContainerBuilder

我是 .Net Core 的新手,如何启用 Autofac 配置?

I am new to .Net Core, how do I enable the Autofac Configuration?

推荐答案

确保调用以下方法一次:GlobalConfiguration.Configuration.UseAutofacActivator(builder.Build());

Make sure you call following method once: GlobalConfiguration.Configuration.UseAutofacActivator(builder.Build());

所以基本上,你需要创建你的构建器

So basicly, you need create your builder

var builder = new ContainerBuilder();

然后添加所有依赖

builder.RegisterType().InstancePerBackgroundJob();

并在此之后调用 Build() 方法.这取决于您的应用程序,在哪里更好地调用此方法.如果您创建一个 Web 应用程序,请在 Startup 类中调用它.

and after this call Build() method. It depends on your app, where call this method better. If you craete a web application, call it in Startup class.

这篇关于Hangfire Autofac .net 核心 3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆