I am building a UI where there are two different behaviors possible based on some configuration. I want my controllers to be loaded dynamically from different Net core assemblies based on a property value "ProductType" - G or P in appsettings.json
appsetings.json
"ProductType" : "G",
In Startup.cs, on reading the value of property "ProductType" I am loading the corresponding assembly to register the controllers only from that library.
Startup.cs
string productType = Configuration["ProductType"];
if (productType.Equals("G", StringComparison.OrdinalIgnoreCase))
{
services.AddMvc()
.AddApplicationPart(Assembly.Load(new AssemblyName("GLibrary")))
}
else if (productType.Equals("P", StringComparison.OrdinalIgnoreCase))
{
services.AddMvc()
.AddApplicationPart(Assembly.Load(new AssemblyName("Plibrary")))
}
Both "GLibrary" and "PLibrary" has a controller/action named as Security/Login but with different implementations.
SecurityController.cs
public IActionResult Login()
{
//Unique Implementation
return View();
}
}
project.json contains entry for both libraries.
project.json
"GLibrary"
"PLibrary"
Now on hitting the Security\Login I am getting this error
An unhandled exception occurred while processing the request.
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
GLibrary.Controllers.SecurityController.Login (GLibrary)
PLibrary.Controllers.SecurityController.Login (PLibrary)
How can I avoid this AmbiguousActionException?