I want to create my own implementation of IControllerFactory and IActionInvoker in an ASP.NET core application. How do I replace the default implementation with my custom class?
I found the solution for older versions of MVC ControllerBuilder.Current.SetControllerFactory
but cannot find a way to do that in ASP.NET core.
I believe I should configure this somewhere in Startup => ConfigureServices
I found a solution by calling
services.AddSingleton<Microsoft.AspNetCore.Mvc.Controllers.IControllerFactory, MyOwnImplementationClassOfControllerFactory>();
right before calling services.AddMvc();
where MyOwnImplementationClassOfControllerFactory
is the custom implementation of IControllerFactory that is derived form DefaultControllerFactory
.
I used singleton, because I found that the default implementation uses the following call services.TryAddSingleton<IControllerFactory, DefaultControllerFactory>();
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