RegisterType 不在 Autofac 2.3.2 中?

发布于 2024-10-01 12:11:27 字数 324 浏览 0 评论 0原文

使用 AutoFac 2.3.2,我尝试执行以下操作:

var builder = new Autofac.ContainerBuilder();
builder.RegisterType<SomeDependency>().As<IDependency>();

RegisterType 不存在。没有通过智能感知看到它,编译器不知道它在那里。查看帮助表明RegisterType方法是一个扩展方法。我有什么遗漏的吗?为什么这个扩展方法没有出现?

我正在使用 VS2010,在测试项目和 Web 应用程序项目中尝试上述代码。

Using AutoFac 2.3.2, I am trying to do the following:

var builder = new Autofac.ContainerBuilder();
builder.RegisterType<SomeDependency>().As<IDependency>();

RegisterType is not there. Not seeing it with intellisense, compiler doesn't know it's there. Looking in the help shows that the RegisterType method is an extension method. Is there something I'm missing? Why is this extension method not showing up?

I'm using VS2010, attempting the above code in a test project and a web application project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池木 2024-10-08 12:11:27

您需要使用use Autofac或直接使用静态方法。

use Autofac;
namespace X
{
   builder.RegisterType<MyType>();
}

或者

Autofac.RegistrationExtensions.RegisterType<MyType>(builder);

You need to use use Autofac or use the static method directly.

use Autofac;
namespace X
{
   builder.RegisterType<MyType>();
}

or

Autofac.RegistrationExtensions.RegisterType<MyType>(builder);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文