Autofac找不到最贪婪的构造函数

Pur*_*ome 5 .net c# dependency-injection autofac

我正在尝试使用Autofac在引用的 dll中找到最贪婪的构造函数.

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

这是两个ctors:

public SimpleAuthenticationController() { .. }

public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider) : this()
Run Code Online (Sandbox Code Playgroud)

现在这是我注册的东西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));
Run Code Online (Sandbox Code Playgroud)

没什么太复杂的.

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

  1. typeof(MvcApplication) 是这个代码存在于的相同项目中 global.asax
  2. typeof(MvcApplication)在-seperate-dll中找到,我手动添加了AddReferences.

有谁看到我做错了什么?

Pur*_*ome 3

问题是我的贪婪调用了,但是如果你看看贪婪的 ctor,你会发现我正在做: this()

这是初学者的错误!

所以它调用了贪婪的 ctor,但在进入作用域之前,它必须冒泡到另一个无参数的 ctor。我一直认为它跳过了贪婪,只是达到了无参数。