在Autofac中注册类,类似于.NET Core默认值

问题描述 投票:1回答:1

我正在使用Autofac作为IoC容器。我以前使用.NET Core的IoC容器并通过以下代码实现了此操作:

serviceCollection.AddSingleton<IConverter>(
    new SynchronizedConverter(new PdfTools()));

如何在Autofac中完成此操作?

c# .net-core dependency-injection autofac
1个回答
2
投票

阅读本:https://autofaccn.readthedocs.io/en/latest/register/registration.html

您可以做类似的事情:

containerBuilder.RegisterInstance(new SynchronizedConverter(new PdfTools()))
    .As<IConverter>();
© www.soinside.com 2019 - 2024. All rights reserved.