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

查看:192
本文介绍了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屋!

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