Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the difference between Domain Handlers and Application Services in Project Silk?
    text
    copied!<p>This is specifically in reference usage of DDD in <a href="http://msdn.microsoft.com/en-us/library/hh404097.aspx" rel="nofollow">Project Silk</a> .</p> <p>The project uses DDD and has the concept of <strong>Handlers</strong> and <strong>Services</strong> implemented. What exactly is the difference and use case for these 2 types?</p> <p>For instance, there is a service <code>UserServices</code> for creation of User. But the creation fo Vehicle is done in a Handler.</p> <p>Would like to know the reasoning behind this decision.</p> <p><strong>Domain\UserServices</strong></p> <pre><code>public class UserServices : IUserServices { private readonly IUserRepository userRepository; public UserServices(IUserRepository userRepository) { if (userRepository == null) throw new ArgumentNullException("userRepository"); this.userRepository = userRepository; } public User CreateUser(User newUser) { if (newUser == null) throw new ArgumentNullException("newUser"); try { Model.User userToAdd = ToDataModelUser(newUser); this.userRepository.Create(userToAdd); return ToServiceUser(userToAdd); } catch (InvalidOperationException ex) { throw new BusinessServicesException (Resources.UnableToCreateUserExceptionMessage, ex); } } } </code></pre> <p><strong>Domain\Handlers\CreateVehicle.cs</strong></p> <pre><code>public class CreateVehicle { private readonly IVehicleRepository _vehicleRepository; private readonly IVehiclePhotoRepository _photoRepository; public CreateVehicle(IVehicleRepository vehicleRepository, IVehiclePhotoRepository photoRepository) { _vehicleRepository = vehicleRepository; _photoRepository = photoRepository; } public virtual void Execute(int userId, ICreateVehicleCommand vehicleForm, HttpPostedFileBase photoFile) { if (vehicleForm == null) throw new ArgumentNullException("vehicleForm"); try { var vehicle = vehicleForm.ConvertToEntity(userId); _vehicleRepository.Create(userId, vehicle); if (photoFile == null) return; // the double reference between vehicle and photo //is a potential source of pain var photo = photoFile.ConvertToEntity(); _photoRepository.Create(vehicle.VehicleId, photo); vehicle.PhotoId = photo.VehiclePhotoId; _vehicleRepository.Update(vehicle); } catch (InvalidOperationException ex) { throw new BusinessServicesException (Resources.UnableToCreateVehicleExceptionMessage, ex); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload