How to separate webapi controllers in your own application domain?

I am thinking of some ideas on how to isolate web api controllers in my โ€œmodulesโ€, which can be combined into a single webapi application. However, I would like to isolate them, and their dependencies form each other, since there will likely be conflicts in version builds. I was wondering if this could be achieved using different application domains for each controller. Anyone have experience with this?

+5
source share
1 answer

Everything that is in the bin folder will be loaded into the current application domain, therefore, as a rule, this is not a problem. However, when avoiding version conflicts, you can use a custom assembly collector to load multiple assemblies / versions into the same AppDomain. This will allow you to connect additional builds to the AppDomain web api.

public class CustomAssemblyResolver : DefaultAssembliesResolver { public override ICollection GetAssemblies() { // load all of your assemblies and return } } 

Then you will replace the default assembly converter for the web api in the configuration.

 config.Services.Replace(typeof(IAssembliesResolver), new CustomAssemblyResolver());
config.Services.Replace(typeof(IAssembliesResolver), new CustomAssemblyResolver()); 

When the web api goes to search for assemblies to find the controllers, it will now use all additional assemblies. See this example for more details.

0
source

Source: https://habr.com/ru/post/1207076/


All Articles