azureazure-service-fabricservice-fabric-statefulreliable-dictionary

Call GetOrAddAsync in the OnOpenAsync method


I use a StatefulService with a IReliableDictionary.

Currently, I call StateManager.GetOrAddAsync<IReliableDictionary> everywhere I need this dictionary.

Is it best practice to call one time only StateManager.GetOrAddAsync<IReliableDictionary> in the OnOpenAsync method of StatefulService and to store the return in a member ?


Solution

  • It does not matter much. I've asked it to the product team an got this response:

    You can cache the result of GetOrAddAsync locally but it doesn't matter since the statemanager does that for you automatically. Some folks think it's easier to keep a local, but I never do because now you have some lifecycle things to deal with (you have a ref to the thing not protected by state manger acquisition locks so you can see some different exceptions, but nothing you wouldn't have to deal with anyway).

    Italic text inserted by me.