Currently, we are trying to implement a custom Controller Factory in our API to determine the correct controller to be used depending on an identifier token that is passed in to our API. The way this project is setup is that each different company (there are only about 5) has its own assembly which contains custom Controllers that has the Action Methods needed to execute whatever action someone is attempting to do. One of the requirements I've been sent is that the controllers must be named the same in these assemblies. So you could have, for example, four different Controllers each in a different assembly all named CustomerController
. These four controllers all contain Action Methods named the same as well but the implementation within them is completely different.
When using our custom Controller Factory, we're using Reflection to pull and create an instance of the correct controller type based off of which Assembly should be targeted. I've debugged this and confirmed that the correct Controller is being returned as a result.
The issue occurring happens during the Action Method call. Even though our Controller Factory is returning the correct controller for our request, it seems that MVC has possibly pre-loaded every controller from these assemblies and is still looking at these as a possible direction. The exact error we're getting on the Action Method getting called is: The current request is ambiguous between the following action methods
Is there any way to tell MVC to ignore the other controllers that were not returned in the request of the controller factory so it will know not to attempt to look at the other controllers that do not seem to be loaded? What is the point of a ControllerFactory if MVC is just going to check all the other controllers for an Action Method match? There must be something I'm missing here.
The only other solution I've found to work around this is adding a ActionMethodSelector attribute to all of the Action Methods involved. However, this makes the solution pretty brittle when looking forward and considering that every single Action Method would need to have the same attribute repeated across them.
Looking forward to any advice or knowledge on why MVC is behaving this way when I have implemented a custom Controller Factory that should be deciding which Controller is chosen for using an Action Method. Thanks in advance!