Events that fire when a hosted service's deployment slot changes (Swap VIP)
开发者_如何学CI have a few settings in my applications that rely on the deployment slot. I understand the penalties and implications such a design decision incurs, but the decision is final and works for our case.
What I would like to know is what events fire when you change a hosted service's Deployment Slot (if any)? The RoleEnvironmentTopologyChange looked correct, but in the decsription it says it fires when the number of instances changes, so that's not what I'm looking for.
The reason I need it is to invalidate the cache that is holding the slot - that is further passed on to the resolver that gets the data specific to the deployment slot.
There's no event that fires during a VIP swap. If you want to change something when you swap, I would recommend making a config setting and changing that before you do the swap.
You can detect a VIP swap by inspecting the host header for each request passed to your WCF or web server from the gateway. You can also detect your current slot by checking if the host is a GUID.
See below on how to persist variables between calls How to write a WCF service with in-memory persistent storage?
var host = WebOperationContext.Current.IncomingRequest.Headers["Host"] ?? "";
if (host != currentHost)
{
// do something
currentHost = host;
}
精彩评论