加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Autofac找不到最贪心的构造函数

发布时间:2020-12-15 05:40:28 所属栏目:百科 来源:网络整理
导读:我正在尝试使用Autofac在引用的dll中找到最贪婪的构造函数. 它找不到它,只找到一个无参数的构造函数. 这是两个ctors: public SimpleAuthenticationController() { .. }public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProv
我正在尝试使用Autofac在引用的dll中找到最贪婪的构造函数.

它找不到它,只找到一个无参数的构造函数.

这是两个ctors:

public SimpleAuthenticationController() { .. }

public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider) : this()

现在这是我用autofac注册的东西:

var builder = new ContainerBuilder();

builder.RegisterType<SampleMvcAutoAuthenticationCallbackProvider>().As<IAuthenticationCallbackProvider>();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterControllers(typeof(SimpleAuthenticationController).Assembly);

var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

没什么太复杂的.

但这是我能想到的唯一奇怪的事情.

> typeof(MvcApplication)与global.asax中存在此代码的项目相同
> typeof(MvcApplication)位于-seperate-dll中,我通过AddReferences手动添加.

有谁看到我做错了什么?

解决方法

问题是我的贪婪 – 被称为..但如果你看着贪婪的人,你会看到我在做:这().

非常蹩脚的新手错误.

所以它正在召唤贪婪的ctor,但在它进入范围之前,它必须冒泡到另一个无参数的ctor.

而且我一直在想它正在跳过贪婪而只是打无参数.

用户和键盘之间的错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读