title: How to avoid violating the DRY principle when you have to have both async and sync versions of code?
body: <p>I'm working on a project that needs to support both async and sync version of a same logic/method. So for example I need to have:</p>
  
  <pre><code>public class Foo
  {
     public bool IsIt()
     {
        using (var conn = new SqlConnection(DB.ConnString))
        {
           return conn.Query&lt;bool&gt;("SELECT IsIt FROM SomeTable");
        }
     }
  
     public async Task&lt;bool&gt; IsItAsync()
     {
        using (var conn = new SqlConnection(DB.ConnString))
        {
           return await conn.QueryAsync&lt;bool&gt;("SELECT IsIt FROM SomeTable");
        }
     }
  }
  </code></pre>
  
  <p>The async and sync logic for these methods are identical in every respect except that one is async and another one is not. Is there a legitimate way to avoid violating the DRY principle in this kind of a scenario? I saw that people say you could use GetAwaiter().GetResult() on an async method and invoke it from your sync method? Is that thread safe in all scenarios? Is there another, better way to do this or am I forced to duplicate the logic?</p>