Search code examples
c#autofacautofac-configuration

Set default ConstructorSelector in Autofac


Autofac has a nice option to set the constructor resolve policy.

e.g. By using the MostParametersConstructorSelector:

builder.RegisterType<MyClass>()
       .AsImplementedInterfaces()
       .UsingConstructor(new MostParametersConstructorSelector());

Is there an option to set the default ConstructorSelector?

I tried:

builder.RegisterType<MostParametersConstructorSelector>().As<IConstructorSelector>();

Can't find it in the docs or source code of Autofac


Solution

  • There is not currently a way to change the finder or selector at the global level. Your best option right now is to wrap that up in an easy extension method and use your extension method as needed.