Detecting configuration changes in code

When we use configuration settings in our roles, such as the AzureBakery.Production.Storage setting we created in the previous chapter, we can change these at runtime in the role's CONFIGURATION tab in the portal:

Detecting configuration changes in code

To detect config changes in code, we can attach event handlers to the RoleEnvironment.Changing event, which is fired before a config change is applied to the role and the RoleEnvironment.Changed event, which is fired after the change has been applied:

public override bool OnStart() { Trace.TraceInformation("OrderProcessorRole.WorkerRole.OnStart - Begin"); RoleEnvironment.Changing += RoleEnvironment_Changing; ...

Get Learning Microsoft Azure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.