0

I have a legacy controller which I want to be a wrapper on the new controller (since for this particular API the legacy and current versions are the same). However when I reference the project of the new service, all of the routes of the new service are also available. So essentially I want only the routes from the current assembly to be configured.

Is this possible by cleanly specifying some option? I can see other questions where people are trying to go the other way (see here), but it doesn't help me.

mft25
  • 417
  • 6
  • 13

1 Answers1

0

You must replace the IHttpControllerTypeResolver service in your HttpConfiguration and only select the type of controllers you want.

Here's a sample which return only the controllers which are in the same assembly with HttpControllerTypeResolver

config.Services.Replace(typeof(IHttpControllerTypeResolver), new HttpControllerTypeResolver());

private class HttpControllerTypeResolver : IHttpControllerTypeResolver
{
    public ICollection<Type> GetControllerTypes(IAssembliesResolver _)
    {
        var httpControllerType = typeof(IHttpController);
        return typeof(HttpControllerTypeResolver)
            .Assembly
            .GetLoadableTypes()
            .Where(t => t.IsClass && !t.IsAbstract && httpControllerType.IsAssignableFrom(t))
            .ToList();
    }
}
Kahbazi
  • 14,331
  • 3
  • 45
  • 76