Static Variable Area in Servie Fabric Application

I run the Service State State Service locally with 3 partitions and 3 replicas.

The application has a public static variable, and the value is initialized in the launch class.

I assumed that the scope of the static variable was on the replica. But it looks like the static scope of variables is shared between all instances in node.

T. I am referring to the static variable from the Primary Replica Partition 1, but it gives the value from the Secondary Replica section 3, where both copies are in the same node . The value of the static variable seems to be overwritten in some order inside the same node.

What is the scope of a static variable in a Stateful service fabric application?

+5
source share
1 answer

Each replica of a state service or service instance without a state of the same service type is an instance of your service class based on StatefulService- or StatelessService (one that has RunAsync) in the same process and in the same AppDomain. In other words, all service replicas hosted on the same node are just a bunch of .NET objects in the same process. So yes, the static variable will be visible through them. Static variables are not recommended. If you need β€œjust one” something, use a singleton template and Singleton instances to serve the replicas / instances that you will have to do with the lookup table.

+7
source

All Articles