What is the equivalent of IHttpControllerSelector for .NET 6?

Viewed 203

We're implementing IHttpControllerSelector in our ASP.NET Web Api (.NET 4.5) for Controller Discovery because some of our Api Controllers resides on a different assembly and we have custom 'routing'(namespace) for it.

config.Routes.MapHttpRoute(
    name: "CustomApi",
    routeTemplate: "{namespace}/api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

Example:

  • Assembly A Controllers will be called assemblyA/api/controllerA/get
  • Assembly B Controllers will be called assemblyB/api/controllerA/get

And so on...

Then we implemented the interface to resolve the controller based on our criteria (code omitted for simplicity).

public class NamespaceHttpControllerSelector : IHttpControllerSelector
{
    public HttpControllerDescriptor SelectController(HttpRequestMessage request)
    {
        //This is where we resolve the controller based on the value of the 'namespace' route.
    }
}

Then while migrating our codes to .NET 6, I couldn't find a way on how to do this. I tried looking for the IHttpControllerSelector interface but it's only available to lower version of .NET Core but not .NET 6. Any ideas on how I can accomplish this same requirement for .NET 6? Thanks.

0 Answers
Related