title: Is this IDisposable returned from a function being disposed of properly?
body: <p>I have a class that performs data access using a <code>SqlConnection</code>, which as we all know implements <a href="https://msdn.microsoft.com/en-us/library/system.idisposable(v=vs.110).aspx" rel="nofollow noreferrer">IDisposable</a> and should be disposed of in a finally block or via a using statement. I have them in using blocks, but my <code>IDisposable</code> is actually created in a separate function. Like this:</p>
  
  <pre><code>public class DataRepository
  {
      private readonly SqlConfiguration _configuration;
  
      public DataRepository(SqlConfiguration configuration)
      {
          _configuration = configuration;
      }
  
      public void Save(Model someModel)
      {
          using(var connection = CreateSqlConnection())
          {
              // Use connection here
          }
      }
  
      public Model Get(int id)
      {
          using(var connection = CreateSqlConnection())
          {
              // Use connection here
          }
      }
  
      private SqlConnection CreateSqlConnection()
          =&gt; new SqlConnection(_configuration.ConnectionString);
  }
  </code></pre>
  
  <p>As you can see, I've got using statements handling all my <code>SqlConnection</code>'s. There is no place that <code>CreateSqlConnection</code> is called outside of a using statement. However, I  am using Code Cracker Roslyn Analyzers and it's giving me a <a href="https://code-cracker.github.io/diagnostics/CC0022.html" rel="nofollow noreferrer">CC0022</a> warning in my <code>CreateSqlConnection</code> that:</p>
  
  <blockquote>
    <p>SqlConnection should be disposed.</p>
  </blockquote>
  
  <p>Have I properly ensured that my <code>SqlConnection</code> is getting disposed of? Is the code analyzer just incorrect in this case?</p>