0

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

Julian
  • 33,915
  • 22
  • 119
  • 174
  • 1
    `DefaultConstructorFinder` is not a constructor **selector**, it's a constructor **finder**. Default **selector** is `MostParametersConstructorSelector`. It's not clear what you're asking then. Also, registration in a container will not work because container will only be built later as a result of registration. Internally Autofac just creates new objects explicitly during registration phase - including default constructor selector. – Alexander Leonov Jun 09 '18 at 03:17

1 Answers1

1

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.

Travis Illig
  • 23,195
  • 2
  • 62
  • 85