title: C# - Repositories versus Services in Supplying Custom Class
body: <p>Good day,</p>
  
  <p>I want to have a clean codes that are basing on the actual enterprise level application. I know how to implement repositories and services but I'm not sure if I'm doing this right.</p>
  
  <p>Suppose, I have a custom class (mostly for json result)</p>
  
  <pre><code>public class CustomClass{
      public string Name { get; set; }
      public string Age { get; set; }
  }
  </code></pre>
  
  <p>I have a model class (connected to my dbcontext)</p>
  
  <pre><code>public class Employees{
      public string Name { get; set; }
      public string Age { get; set; }
  }
  </code></pre>
  
  <p>Here's my 1st sample repository that supplies the Custom Class</p>
  
  <pre><code>// in repository file only
  public IEnumerable&lt;CustomClass&gt; SupplyCustomClass(){
       return context.Employees.Select(obj=&gt;new CustomClass{
            Name = obj.Name,
            Age = obj.Age
       }).ToList();
  }
  </code></pre>
  
  <p>Here's my 2nd sample, the repository is supplies the first then followed by service.</p>
  
  <pre><code>// in repository file (EmployeeRepo)
  public IEnumerable&lt;Employees&gt; SupplyEmployeeFirst(){
       return context.Employees.ToList();
  }
  
  // in service file
  // dependency injection from EmployeeRepo
  public IEnumerable&lt;CustomClass&gt; SupplyCustomClassSecond(){
       var customClass = new List&lt;CustomClass&gt;();
  
       var employees = employeeRepo.SupplyEmployeeFirst();
  
       foreach(employee in employees){
           customClass.Add(new CustomClass{
               Name = obj.Name,
               Age = obj.Age
           });
       }
  
       return customClass;
  }
  </code></pre>
  
  <p>Both implementation execute the same result. But I want to learn what's the best way in order to follow the rule in enterprise development level. </p>