What .NET features will allow me to load “reload” and “restart” an embedded server? I don’t know how to ask this question well. I’m writing a server that needs to be updated periodically with additional features. I want it to run 2 of the same server on different ports (for redundancy) and then when I roll out new changes take one of the servers down, load the new code, run tests, start moving traffic to the new version and then begin the same process on the second server.
I’m thinking that maybe AppDomains or MEF might be what I’m looking for, but don’t know much about these technologies. I’m wondering if there might be something else already in the .NET framework that I’m missing that would help out.
Any suggestions? If I’m off about the AppDomains or MEF feel free to let me know that as well.
I do this in a windows service with AppDomains. The service just has the network-IO code, and the code to download new versions and instantiate app-domains. All the real code is behind a well-known and unchanging interface, which has the “handle a request” code, and the serialize/deserialize mechanisms for long-term local state.
The upshot is that the single service can run perpetually. When a new version is available and has passed the smoke-test, it can simply change a single reference (the marshalled/unwrapped instance), and hey presto: upgraded. It can then unload the old app-domain.
For redundancy (hardware etc) we still use multiple nodes for this, with load-balancing applied at the client (although you could d this at a NLB too; we had reasons not to this time).