ASP.NET Web.Api plugin architecture
asp.net, asp.net-web-api
Solution
For locating controller classes at run time, you can write an assembly resolver, like this.
public class MyAssembliesResolver : DefaultAssembliesResolver
{
public override ICollection<Assembly> GetAssemblies()
{
List<Assembly> assemblies = new List<Assembly>(base.GetAssemblies());
// Add all plugin assemblies containing the controller classes
assemblies.Add(Assembly.LoadFrom(@"C:\Plugins\MyAssembly.dll"));
return assemblies;
}
}
Then, add this line to the `Register` method in `WebApiConfig`.
config.Services.Replace(typeof(IAssembliesResolver), new MyAssembliesResolver());
With this, the request will still need to be sent to the individual controller even though the controller classes can come from assemblies in the plugin folder. For example, if MyAssembly.dll in the plugins folder contains `CarsController`, the URI to hit this controller will be /api/cars.
Problem
Can you suggest me some articles or code samples about plugin architecture in web api? Currently I'm thinking about this scenario: to have 1, centralized api gateway, where every client sends request, and have different applications controllers in Plugins folder. If someone wants to add new service, writes it's own controllers and puts dll files in Plugin folder.