ASP.NET Web.Api Plugin Architecture

Can you offer me some articles or code examples on plugin architecture in web api?

I am currently thinking of this scenario: have 1, a centralized Api gateway where each client sends a request and has different application controllers in the Plugins folder. If someone wants to add a new service, he writes his own controllers and puts the DLL files in the Plugin folder.

+8
asp.net-web-api
source share
1 answer

To find controller classes at runtime, you can write an assembly converter, for example:

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()); 

In this case, the request will still need to be sent to a separate controller, even if 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 click on this controller will be / api / cars.

+4
source share

All Articles