I am developing .NET WEB Api REST Service using framework 4.5 and the architectural direction now is to separate functional areas of our API. In other words, placing controllers into separate assemblies, e.g. having controllers in assemblies like company.web.administration, company.web.claims, etc.
After experimenting with it, I noticed the power of the MVC framework. I can place controllers into separate class libraries but as long as these libraries are in the bin folder, they don’t even have to be referenced. MVC finds them in the assemblies and API calls work fine.
But under this architecture, the problem arises that we might get large number of these controller libraries. So, it would be helpful to pack them together under bin\controllers, for example.
Dropping controllers into sub-folder ceases ability of ASP.NET MVC WEB API Framework to find them.
I am searching for a way to tell Framework to look for these controllers under my directories as well as in bin. One of the options I used is I modified Web.config file as following:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin\controllers;controllers"/>
</assemblyBinding>
</runtime>
That didn’t work. Any ideas?
A while ago, I have written a blog post about how to do that – http://www.strathweb.com/2012/06/using-controllers-from-an-external-assembly-in-asp-net-web-api/
Basically, you need to roll out your own
IAssembliesResolveror override theGetAssemblies()method ofDefaultAssembliesResolver.