title: 3 layer architecture in a Winform App
body: <p>I'm trying to implement this architecture for the first time in a Winform. So I have a simple but very important question for me.
  Take a simple example. I want the form to retrieve a user list and to allow a modification of the phone number.
  I have this for the first step (simplified and I normally use interfaces)</p>
  
  <pre><code>public Form1()
  {
      InitializeComponent();
      UserService _userService = new UserService();
      listBoxUsers.DataSource = _userService.GetAllUsers();
  }
  class User
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public string Phone { get; set; }
  }
  class UserService
  {
      UserRepository _userRepository=new UserRepository();
      public Dictionary&lt;int, string&gt; GetAllUsers()
      {
          DataTable dtbl= _userRepository.AllUsers();
          //Some code here
          return dict;
      }
  }
  class UserRepository
  {
      public DataTable AllUsers()
      {
          //Sql query
          return dtbl; 
      }
  }
  </code></pre>
  
  <p>Now by selecting a user in the lisbox, I'm able to display some information as the Phone number.  When I'm changing the phone number, I need a method called UpdatePhoneNumber to update the SQL database.
  But, where to place it? User or UserService (I don't talk about the SQL query, just the logic)
  And after that, how to access  (here or somewhere else in the app) to this user property to display it in the form? Directly with _user.Id (User must be instantiated in the form) or implement a _userService.The id which retrieves User.ID (in this case Form knows only UserService class).
  Many thanks for your precious help</p>