title: Design Pattern: Managing an async task across application layers
body: <p>New to writing async methods using Tasks in C#.  This is a question about how to architect calling an async task from across application layers.</p>
  
  <p>I have a Data Access layer that makes REST calls to a server.  I have implemented Async methods for each server call, that each return a Task.</p>
  
  <p>I have a Business Logic layer that makes the calls to the Data Access layer.  Requests to the business logic layer that are asynchronous take a callback, which would get executed once the Task completes using <code>ContinueWith()</code>.  Details of the asynchronous execution are thus contained to the Business Logic layer.</p>
  
  <p>I'm wondering if this kind of design choice makes sense, or if it would be better for my Business Layer to pass the Task object up to its caller?</p>
  
  <p>Here's an example of my <code>DateManager</code> which I have so far.  Without <code>await</code>, I wrote it like I have here.  However, from my view controller, calling <code>DateManager.GetTradeDate()</code> with the callback might be awkward now.</p>
  
  <pre><code>public class DateManager : IDateManager
  {
      public void GetTradeDate(string dt, Action&lt;string&gt; callback)
      {
          DateManagerClient dmc = new DateManagerClient();
          Task&lt;string&gt; t = dmc.GetTradeDateAsync(dt);
          t.ContinueWith(x =&gt;
          {
              callback(x.Result);
          });
      }
  }
  </code></pre>