domain driven design - Value Object as a Service Call Argument -


in book implementing ddd, there's mention of creating tenantid value object. makes sense me, guid empty isn't valid tenantid, making tenantid value object can protect against (i have other value objects name, phonenumber, emailaddress, etc):

public class tenantid {     public tenantid(guid id)     {         this.setid(id);     }      public guid id { get; private set; }      private void setid(guid id)     {         if (id == guid.empty)         {             throw new invalidoperationexception("id must not empty guid.");         }          this.id = id;     } } 

what i'm interested in, should i, or should not, use tenantid on service method, like:

tenantid tenantid = new tenantid(model.tenantid); // model.tenantid being guid.  this.tenantservice.gettenant(tenantid); 

or should use more raw form in service method arguments:

this.tenantservice.gettenant(model.tenantid); // again model.tenantid guid. 

the book seems 1 way , sometime another. thoughts people have on pros , cons of these approaches?

if service doesn't require restricted access entity, pass value object since shared identifier, code this:

public class tenantid : iequatable<tentantid> {     public tenantid(guid id)     {         if (id == guid.empty)         {             throw new invalidoperationexception("tenantid must not empty guid.");         }         _id = id;     }      private readonly guid _id;      public equals(tentantid other)     {         if (null == other) return false;         return _id.equals(other._id);     }      public gethashcode()     {         return _id.gethashcode();     }      public override equals(object other)     {         return equals(other tenantid);     }      public tostring()     {         return _id.tostring();     } } 

however in cases, domain service should invoked entities user can access in repository: in cases, public interface of domain service require entity (even if implementation use identifier).


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -