title: Best practices for Service/Repository pattern and async await APIs
body: <p>I am pretty much new using Service/Repository pattern. This is the code I have so far:</p>
  
  <pre><code>public interface IRepository&lt;T&gt; where T : class
  {
      Task&lt;IEnumerable&lt;T&gt;&gt; GetAll();
  }
  
  
  public interface IUserRepository : IRepository&lt;User&gt;
  {
  
  }
  
  
  public class UserRepository : IUserRepository
      {
          public async Task&lt;IEnumerable&lt;User&gt;&gt; GetAll()
          {
              List&lt;User&gt; lst = new List&lt;User&gt;();
              lst.Add(new User { ID = 1, Code = "001", Username = "dfrancisco", Password = "dfrancisco123" });
              lst.Add(new User { ID = 1, Code = "002", Username = "111", Password = "1231!" });
              lst.Add(new User { ID = 1, Code = "003", Username = "22", Password = "asdasd1!" });
              lst.Add(new User { ID = 1, Code = "004", Username = "334", Password = "asdasd1" });
              lst.Add(new User { ID = 1, Code = "005", Username = "55", Password = "13" });
  
              return lst;
          }
      }
  
  
  public class UserService : IUserService
      {
          private readonly IUserRepository _userRepository;
  
          #region Constructors
  
          /// &lt;summary&gt;
          /// constructor for UserService
          /// &lt;/summary&gt;
          /// &lt;param name="UserRepository"&gt;&lt;/param&gt;
          public UserService(IUserRepository UserRepository)
          {
              _userRepository = UserRepository;
          }
  
          public async Task&lt;IEnumerable&lt;UserDTO&gt;&gt; GetAll()
          {
              List&lt;User&gt; data = (await _userRepository.GetAll()).ToList();
  
  
              List&lt;UserDTO&gt; dtos = new List&lt;UserDTO&gt;();
              foreach (User item in data)
              {
                  dtos.Add(new UserDTO { Username = item.Username });
              }
  
              return dtos;
             // throw new NotImplementedException();
          }
          #endregion
      }
  </code></pre>
  
  <p>So, I wanted to know if this es the correct approach to use such a design pattern. I have seen many examples online using this code to return data in this kind of methods :</p>
  
  <pre><code>return await _repository.GetAll(eppPlanId);
  </code></pre>
  
  <p>Or this ..</p>
  
  <pre><code>return await Task.Run(() =&gt; eppPlanDetails);
  </code></pre>
  
  <p>The case I propose is just to demonstrate a random business logic required. So, I would like to understand what are the differences in these approaches and what is the one I should use.</p>