ControllerActivator should be able to use controllers registered as services #1707
Comments
We think we can do this without the additional extension method. |
Based on discussion with @lodejard \ @yishaigalatzer
|
services * Added WithControllersFromServiceProvider that replaces the default controller activator with a service based one. * Move activation to DefaultControllerFactory * Modify [Activate] behavior so that it no longer activates services. Use [FromService] attribute to hydrate services Fixes #1707
Additional requirements:During controller discovery, controller types in the application that are not registered in the service container should not be considered as controllers. The intent is to
Implementation design:
Usage:services.AddMvc()
.WithControllersFromDI()
.RegisterController(typeof(FooController))
.RegisterController<QuxController>()
.RegisterControllers(new[] { typeof(BarController), typeof(BazController) }); |
services * Added WithControllersFromServiceProvider that replaces the default controller activator with a service based one. * Move activation to DefaultControllerFactory * Modify [Activate] behavior so that it no longer activates services. Use [FromService] attribute to hydrate services Fixes #1707
services * Added WithControllersFromServiceProvider that replaces the default controller activator with a service based one. * Move activation to DefaultControllerFactory * Modify [Activate] behavior so that it no longer activates services. Use [FromService] attribute to hydrate services Fixes #1707
services * Added WithControllersFromServiceProvider that replaces the default controller activator with a service based one. * Move activation to DefaultControllerFactory * Modify [Activate] behavior so that it no longer activates services. Use [FromService] attribute to hydrate services Fixes #1707
Just wondering, why was this implemented the way that it is instead of tapping into the options system? Meaning why do we have My only thought is that you were trying to make it more explicit and if it was on |
That's a good question. It's mostly because the controllers list is computed as late as possible, and options typically have specific types rather than providers. Honestly this could have gone both ways. |
@yishaigalatzer Thanks for filling me in. I was just confused when I saw two different strategies for doing very similar things. |
Something like:
This would replace the default activator with one that gets the controllers from DI.
This replaces #1700
CC @lodejard @davidfowl @halter73 @pranavkm @yishaigalatzer
The text was updated successfully, but these errors were encountered: