We are currently trying to implement the Factory user controller in our API to determine the correct controller that will be used depending on the identifier token that is passed to our API. The way this project is set up is that each other company (about 5 in total) has its own assembly, which contains user controllers that have action methods needed to perform any action that someone is trying to do. One of the requirements that I sent is that the controllers must be the same in these assemblies. Thus, you can have, for example, four different controllers each in a different assembly, all with the nameCustomerController. For these four controllers, all Action methods are called the same, but the implementation inside them is completely different.
When using our custom Factory controller, we use Reflection to pull and instantiate the correct type of controller on which the assembly should be targeted. I debugged this and confirmed that the correct controller is returned as a result.
The problem occurs when the action method is called. Despite the fact that our Factory controller returns the correct controller for our request, it seems that MVC may have preloaded each controller from these assemblies and still considers them as a possible direction. The exact error we get from the action method being called:The current request is ambiguous between the following action methods
Is there a way to tell MVC to ignore other controllers that were not returned in the request of the Factory controller so that it does not know, so as not to try to look at other controllers that do not seem to load? What is the point of ControllerFactory if MVC just checks all the other controllers to match the Action Method? There must be something missing here.
The only other solution I found for this is to add the ActionMethodSelector attribute to all the involved action methods. However, this makes the decision rather fragile, if you look ahead, and believing that each method of action should have the same attribute, repeated through them.
, MVC , Factory, , . !