I'm trying to use Autofac to find the most greedy constructor in a referenced dll.
我尝试使用Autofac在一个引用的dll中找到最贪婪的构造函数。
It's not finding it and only finds the one parameterless constructor.
它没有找到它,只找到一个无参数的构造函数。
These are the two ctors:
这是两个c:
public SimpleAuthenticationController() { .. }
public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider) : this()
Now this is how I register the stuff with autofac
:
这是我如何向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));
nothing too complex.
没有什么太复杂。
But this is the only weird thing I can think of.
但这是我能想到的唯一奇怪的事情。
-
typeof(MvcApplication)
is the same project where this code exists in, inglobal.asax
- typeof(MvcApplication)是该代码存在于global.asax中的同一个项目。
-
typeof(MvcApplication)
is found in a -seperate- dll, which I manually added viaAddReferences
. - MvcApplication类型是在一个-seperate- dll中找到的,我通过地址手动添加了它。
Anyone see what I've done wrong?
有人知道我做错了什么吗?
1 个解决方案
#1
2
Problem was that my greedy -was- getting called .. but if u looked at the greedy-ctor, you'll see that i'm doing : this()
.
问题是我的贪心正在被召唤…但是如果你看看这个贪婪的人,你会发现我在做:this()
very lame newbie error.
很蹩脚的新手的错误。
So it was calling the greedy ctor, but before it goes into scope, it has to bubble up to the other parameterless ctor.
它调用了贪婪的ctor,但在它进入作用域之前,它必须冒泡到另一个无参数的ctor。
And I kept thinking it was skipping the greedy and just hitting the parameterless.
我一直在想,它跳过了贪婪的部分,而只是撞到了无参数的部分。
Error Between User And Keyboard.
用户和键盘之间的错误。
#1
2
Problem was that my greedy -was- getting called .. but if u looked at the greedy-ctor, you'll see that i'm doing : this()
.
问题是我的贪心正在被召唤…但是如果你看看这个贪婪的人,你会发现我在做:this()
very lame newbie error.
很蹩脚的新手的错误。
So it was calling the greedy ctor, but before it goes into scope, it has to bubble up to the other parameterless ctor.
它调用了贪婪的ctor,但在它进入作用域之前,它必须冒泡到另一个无参数的ctor。
And I kept thinking it was skipping the greedy and just hitting the parameterless.
我一直在想,它跳过了贪婪的部分,而只是撞到了无参数的部分。
Error Between User And Keyboard.
用户和键盘之间的错误。