I want to use AutoFac to inject references into an object’s constructor. However, the actual object itself is not registered. I am doing this for an ASP.NET MVC controller factory, where the controller won’t be registered, but the constructor params will be. I managed to do this in unity, but I am having trouble with AutoFac.
Is that possible?
Thanks.
Autofac can’t resolve a type that hasn’t been registered, even when this type is concrete with a single public constructor.
In your situation this problem however can be solved easily, because there is an Mvc3Ingegration package for Autofac that contains a
RegisterControllersextension method for the builder. You can use it as follows: