While developing new solutions, we often use Service Fabric services as controllers. Executing actions on demand, checking the status of other Azure services, running maintenance routines, cleaning up data, the possibilities with Service Fabric are endless. Often, that means we have a cluster of services deployed to different environments, but want to disable a particular service.
Once this basic setup is done, each service's Main method can decide which service to instantiate, the NoopService if the service is disabled in the configuration setting, or the real service if it isn't:
In our Application Parameters file, we can now simply provide a value for the 'Enabled' configuration setting to enable or disable a service by environment.
As you can see, the principle behind this disabling is simple, yet offers us a lot of power: we can disable a service without changing its InstanceCount, we can choose exactly which services to enable in which environment, and we can disable a service without impacting any other operation. The service will show up as having healthy instances, but won't do anything.
Additionally, this has proven very useful during debugging on the local cluster. We can disable the entire application except the service we want, and so debug it in complete isolation.