开发者

Provide the ability to "hot swap" / change assemblies at runtime without re-starting a process

开发者 https://www.devze.com 2023-01-20 04:09 出处:网络
ASP.Net allows you to copy new assemblies into the bin directory of an application without needing to re-start any services or processes.

ASP.Net allows you to copy new assemblies into the bin directory of an application without needing to re-start any services or processes.

I have an application that loads user defined plugins and extensions (some of them are COM based) - I'd like to provide similar functionality (i.e. the ability to change / update an assembly without needing to re-start the process). Currently开发者_如何学编程 the assembly is locked until the process is stopped.

How does ASP.Net manage this?


ASP.Net achieves this by using "Shadow Copying". See here: MSDN Shadow Copying

Basically the assemblies are copied to a different folder by ASP.Net from which they are loaded into an App Domain. It is this copied version of the assembly that is locked by the process leaving the original assembly file (in the Bin folder) unlocked. The App Domain is then configured to monitor the original assembly for changes and in the case that an update is detected a new App Domain is created and the new assembly loaded into it.

At this point, any future requests to the web application are routed by ASP.Net to the new App Domain while the old App Domain is kept alive to continue serving any currently executing requests through to completion. When ASP.Net determines that the old App Domain is no longer handling any requests it is unloaded and the "hot swap" is complete.

From your brief description though I would recommend looking into Microsoft MEF. MEF is a framework dedicated to building the kind of plugin architectures you are describing.

0

精彩评论

暂无评论...
验证码 换一张
取 消