I'm trying to use Autofac to find the most greedy constructor in a referenced dll.
It's not finding it and only finds the one parameterless constructor.
These are the two ctors:
public SimpleAuthenticationController() { .. }
public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider) : this()
Now this is how I register the stuff with 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, in global.asax
typeof(MvcApplication)
is found in a -seperate- dll, which I manually added via AddReferences
.Anyone see what I've done wrong?
Problem was that my greedy was getting called, but if you looked at the greedy-ctor, you'll see that I'm doing : this()
.
This was a beginner error!
So it was calling the greedy ctor, but before it goes into scope, it has to bubble up to the other parameterless ctor. And I kept thinking it was skipping the greedy and just hitting the parameterless.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With