My WebApi controllers are located in an assembly (self-hosted OWIN application or ASP MVC application). Is it possible to use ApiExplorer form another application (that loads an assembly with WebApi controllers dynamically) to generate Web API documentation?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
ApiExplorer uses the GlobalConfiguration to determine the available ApiControllers. When you specify an external assembly you typically do this by replacing the IAssemblyResolver that WebApi is using. This can be done in Application_Start like this:
Here's the implementation of AssemblyResolver:
One might think that this is enough for ApiExplorer to pick it up but it is not. When ApiExplorer starts the GlobalConfiguration is passed to the HelpController. If you look carefully at the instance of GlobalConfiguration you will see that the changes you affected in your Application_Start are not there. So, to get ApiExplorer to pick up your external class you can just update the IAssemblyResolver like this:
There is probably a cleaner way to do this so you don't break DRY - but have not found it yet. Will update this post when I find it.