title: Another application architecture question
body: <p>I am trying some DDD and I will try to describe in most simple manner what I have done.</p>
  
  <p><strong>Core project</strong><br>
   The core project contains Entities, VO and domain services. For example I have <em>User</em> entity and <em>UserRelation</em> entity. I think we all know what is the <em>User</em> entity. The <em>UserRelation</em> contains information about how users are connected to each other like follow and connect(bidirectional follow). Because of that I have <em>UserDomainService</em> with stateless methods like Follow(user,user) and Connect(user, user).</p>
  
  <pre><code>public class User
  {
      public string Name { get; set; }
      public string Username { get; set; }
  
      public void ChangeUsername(stirng newUsername)
      {
          ApplyEvent(new UserUsernameChanged(newUsername));
      }
  }
  
  public class UserRelation
  {
      ctor(User1, User2, isBidirectional)
      public User User1 { get; set; }
      public User User2 { get; set; }
      public bool IsBidirectional { get; set; }
  }
  
  public class UserDomainService
  {
      public UserRelation Follow(User user1, User user2)
      { 
          return new UserRelation(user1,user2,false);
      }
  }
  </code></pre>
  
  <p><strong>Repository Project</strong>  </p>
  
  <p>I am using NHibernate so I decided to not create such a project. Instead I am using NHibernate directly. For example, in my UI I get a user object from the DB, change it and then call session.Save(user).</p>
  
  <p><strong>The problem</strong>   </p>
  
  <p>If I want to do operation like follow I do this:</p>
  
  <ul>
  <li>Get some info from DB</li>
  <li>Call the Follow(user1, user2) from the service</li>
  <li>Save the UserRelation object to the DB
  In the end the application code becomes a bit complex. Imagine if we want to use this code in 2-3 places and at some point we have to refactor it.</li>
  </ul>
  
  <p><strong>My solution</strong><br>
  My solution is to create a ApplicationService project which will do the dirty work and force the consumer to use ApplicationService instead of using Entitties and Domain services directly</p>
  
  <pre><code>public class UserApplicationService
  {
      ctor(UserDomainService userDomainService){}
  
      User GetUser(Guid id)
      {
          return NhibernateSession.Get(id)
      }
  
      public void Follow(Guid user1Id, Guid user2Id)
      {
          var u1 = GetUser(user1Id);
          var u2 = GetUser(user2Id);
          var userRelation = _userDomainService.Follow(u1,u2);
          NhibernateSession.Save(userRelation);
      }
  
      public void ChangeUsername(Guid user, string newUsername)
      {
          user.ChangeUsername(newUsername);
          NhibernateSession.Save(user);
      }
  }
  </code></pre>
  
  <p>Is this application service good or bad? As you can see the new service act also as a repository so we can create a UserRepository class but lets skip that for now. What bothers me is the parameters in the two methods. They accept Guids and the service retrieves users from the DB. The other option is to pass directly User object. The ChangeUsername method is like the one from User entity + persistence.</p>
  
  <p>Well, what do you think about this?</p>