title: Re-using reference to an IReliableCollection
body: <p>Is it acceptable to re-use a reference to a <code>IReliableCollection</code> or should I request from <code>IReliableStateManager</code> every time I want to use it?</p>
  
  <p>For example, if I have a dictionary that is widely used in my application, is it acceptable to retrieve it once in the <code>RunAsync</code> method and then pass this reference to any method that requires it, e.g:</p>
  
  <pre><code>protected override async Task RunAsync(CancellationToken cancellationToken)
  {
      _someCollection = StateManager.GetOrAddAsync&lt;IReliableDictionary&lt;int, string&gt;&gt;(
          "SomeName");
  }
  
  public async Task DoSomething(int id, string message)
  {
      _someClass.DoSomething(_someCollection, id, message);
  }
  </code></pre>
  
  <p>And then use in a class like so:</p>
  
  <pre><code>public class SomeClass 
  {
      public void DoSomething(IReliableDictionary&lt;int, string&gt; dict, int id, string msg)
      {
          using (ITransaction tx = StateManager.CreateTransaction()) 
          {
              await dict.AddAsync(tx, id, msg);
              await tx.CommitAsync();
          }
      }
  }
  </code></pre>
  
  <p>Or should I request from <code>IReliableStateManager</code> on each call, e.g,</p>
  
  <pre><code>public class SomeClass 
  {
      public void DoSomething(int id, string msg)
      { 
          var dict = StateManager.GetOrAddAsync&lt;IReliableDictionary&lt;int, string&gt;&gt;("SomeName");
  
          using (ITransaction tx = StateManager.CreateTransaction()) 
          {
              await dict.AddAsync(tx, id, msg);
              await tx.CommitAsync();
          }
      }
  }
  </code></pre>
  
  <p>Passing a reference seems to work fine from what I can tell but I'm not sure whether this would be considered bad practice and I can't find a definitive answer in the <a href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-reliable-collections-guidelines" rel="nofollow noreferrer">guidelines</a> or <a href="https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-work-with-reliable-collections" rel="nofollow noreferrer">documentation</a></p>