.net - What is the difference between Domain Handlers and Application Services in Project Silk? -
this in reference usage of ddd in project silk .
the project uses ddd , has concept of handlers , services implemented. difference , use case these 2 types?
for instance, there service userservices
creation of user. creation fo vehicle done in handler.
would know reasoning behind decision.
domain\userservices
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); } } }
domain\handlers\createvehicle.cs
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; // double reference between vehicle , photo //is 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); } } }
in example, think difference creation of user active action of user while creation of viecle passive one. submits form create user, on other hand, triggers create viecle after operation done(maybe after user created?).
maybe you'll interested in answer.
Comments
Post a Comment