title: Extension Method for Polly Policy
body: <p>I am trying to find the best way to write an extension method for Polly Policy </p>
  
  <p>I have the following </p>
  
  <pre><code>public static async Task&lt;IPollyDto&gt; RunAsync(this IPolicy dtoClass, Func&lt;Task&lt;IDto&gt;&gt; action)
  {
      return
          await Policy
              .Handle&lt;ApiException&gt;(ex =&gt; ex.StatusCode == HttpStatusCode.RequestTimeout)
              .RetryAsync(3,
                  async (exception, retryCount) =&gt; await Task.Delay(200))
              .ExecuteAsync(async () =&gt; await action.Invoke().ConfigureAwait(false))
              .ConfigureAwait(false);
  }
  
  public interface IPollyDto {}
  public interface IPolicy {}
  </code></pre>
  
  <p>Then I call the code as follows</p>
  
  <pre><code>public class DtoTest : IPollyDto
  {
  }
  
  public class TestA
  {
      public static async Task&lt;DtoTest&gt; GetItem(string datasetName)
      {
          return await Task.Run(() =&gt; new DtoTest()) ;
      }
  }
  
  public class PollyTest : IPolicy
  {
      public async Task&lt;DtoTest&gt; TestMe(string dataset)
      {
         return (DtoTest) await this.RunAsync(() =&gt; Task.Run(() =&gt; (IPollyDto) TestA.GetItem(dataset)));
      }
  }
  </code></pre>
  
  <p>I get an error resolving types.</p>