Hangfire Autofac .net core 3.1 [英] Hangfire Autofac .net core 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< Database>().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 core 3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!