I’ve architected a back-end in such a way that the business logic is placed in dlls that are loaded at run-time. Using ShadowCopyFiles = true, and filesystem monitoring, I am able to modify business logic without restarting the host process.
So far so good…
Let’s call the host appdomain A, and one of the children B.
Unfortunately, if I make changes in an assembly C, which is referenced by B but not A, these changes are not reflected when B is reloaded. I assume it is because A loads C itself. What steps do I have to take to prevent A from loading C?
This is the code used by A to load B:
AppDomainSetup appDomainSetup = new AppDomainSetup();
appDomainSetup.CachePath = ServiceDLLPath + @"\Shadow";
appDomainSetup.ShadowCopyFiles = "true";
ad = AppDomain.CreateDomain(assemblyName, null, appDomainSetup);
ad.InitializeLifetimeService();
try
{
service = (IService)ad.CreateInstanceFromAndUnwrap(assemblyName,
"AppName.Services." + typeName);
service.Start();
}
catch (Exception e)
{
LogManager.Log("AppDomain load failed: " + e.Message);
return false;
}
If
AreferencesCandAis the ‘host’, you cannot reloadCwithout stopping and restarting the process.One possibility would be to make an extremely thin shim AppDomain that bootstraps the
AAppDomain (and can restart it), but retsrating the process would probably be about the same performance profile.The other (seemingly saner) approach would be to make
Aand it’s dependencies independent of those used byC, and for the overlapping assemblies just make them stable enough that you don’t need to change them very often.