title: C# Implement an interface on web api
body: <p>I'm working on a new microservice and would like the to put an interface on the API for my clients.</p>
  
  <p>For example.<br>
  I have a customer service with ApiController and a method:</p>
  
  <pre><code>[HttpGet("api/v1/[action]")]
  [ProducesResponseType((int)HttpStatusCode.BadRequest)]
  [ProducesResponseType((int)HttpStatusCode.NotFound)]
  [ProducesResponseType(typeof(List&lt;CustomerDto&gt;), (int)HttpStatusCode.OK)]
  public async Task&lt;IActionResult&gt; GetCustomers()
  {
      Log.Logger.Information($"Calling GetCustomers()");
      var ret = await _db.Customer.GetListAsync&lt;CustomerDto&gt;();
      Log.Logger.Information($"GetCustomers()=&gt;{ret?.Count}");
      if (ret == null)
      {
          return NotFound();
      }
          return Ok(ret);
      }
  </code></pre>
  
  <p>In my client code I have a service interface that abstracts the HTTP calls to the above service. So my client using this service can simply inject a <code>ICustomerService</code> and call <code>GetCustomers()</code>.</p>
  
  <p>This is all working great, however would I really want is to put an the same <code>ICustomerService</code> interface on the API controller, so I can catch any issues at compile time. The problem is that <code>ICustomerService.GetCustomer</code> returns  <code>List&lt;CustomerDto&gt;</code> and the controller returns <code>IActionResult</code>.</p>
  
  <pre><code>Task&lt;List&lt;CustomerDto&gt;&gt; GetCustomers();
  </code></pre>
  
  <p>VS</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; GetCustomers(){}
  </code></pre>
  
  <p>Is there a way to enforce the <code>ICustomerService</code> interface on the API controller at build time?</p>