title: Parsing usercontent into repository. Which approach is better?
body: <p>after reading about many different design patterns i got a question about my current project and I hope somebody can help me.</p>
  
  <p>My project takes different user files as input and transforming them into a repository of objects for easy use.</p>
  
  <p>For example:</p>
  
  <pre><code>Userfile A with the content: 
  "id:a" - "value1:contentA1" - "value2:contentB1" 
  "id:b" - "value1:contentA2" - "value2:contentB2" 
  "id:c" - "value1:contentA3" - "value2:contentB3"
  </code></pre>
  
  <p>Now i see two different approaches to parse this file into objects (which is better?):</p>
  
  <p><strong>1)</strong></p>
  
  <p>We got a entity class:</p>
  
  <pre><code>public class UserContent
  {
      public int ID { get; set; }
      public string Value1 { get; set; }
      public string Value2 { get; set; }
  }
  </code></pre>
  
  <p>A service which takes a line of the user file and parses it into the object:</p>
  
  <pre><code>public class UserContentParser
  {
      public UserContent ParseUserContent(string content)
      {
          // ...
          // splitting the content
          // ...
          return new UserContent
                              { 
                                  ID = id,
                                  Value1 = value1,
                                  Value2 = value2
                              };
      }
  }
  </code></pre>
  
  <p>A ParseController:</p>
  
  <pre><code>public class ParseController
  {
      private Repository _repository = new Repository();
      private UserContentParser _userContentParser = new UserContentParser();
  
      public Repository StartParsing(File userFile)
      {
          // ...
          // reading file
          // ...
          foreach(var contentLine in userFileContent)
          {
              _repository.AddUserContent(_userContentParser.ParseUserContent(contentLine));
          }
      }
  }
  </code></pre>
  
  <p>The other approach I see is the following:</p>
  
  <p><strong>2)</strong>
  This approche just consits of two classes (no service class):</p>
  
  <pre><code>public class UserContent
  {
      public UserContent(string content)
      {
          // ...
          // splitting the content
          // ...
          ID = id;
          Value1 = value1;
          Value2 = value2;
      }
  
      public int ID { get; set; }
      public string Value1 { get; set; }
      public string Value2 { get; set; }
  }
  
  public class ParseController
  {
      private Repository _repository = new Repository();
      private UserContentParser _userContentParser = new UserContentParser();
  
      public Repository StartParsing(File userFile)
      {
          // ...
          // reading file
          // ...
          foreach(var contentLine in userFileContent)
          {
              _repository.NewUserContent(contentLine);
              // in this method the repository creates the 
              // new UserContent(contentLine)
          }
      }
  }
  </code></pre>
  
  <p>The projects also contains some plugins, which are getting a reference to the repository to work with the containing objects.</p>
  
  <p>Which approach is better here? Is there maybe a better alternative? And what happens if other dependencies are needed to parse the user content? Is it ok if the entity depends on services or is it better to have no dependencies in entity objects? And even one more question, is the UserContent class a DTO because it is used to parse user content into it an passing it to other plugins?</p>
  
  <p>I hope someone can help me with my many questions.</p>
  
  <p>Regards,
  Gerrit</p>