3

I have an ASP.NET MVC web site working in this way:

(In the controller)

var user = _applicationService.GetUserById(1);
user.ChangeEmail("[email protected]");
user.ChangeAddress("my new street", "21");

(In a HttpModule)

void EndRequest(){
 if (HttpContext.Error is null){
 _sessionFactory.GetCurrentSession.Transaction.Commit();
 }

This way is possible because the session factory is built in the web site application start. It is possible to call multiple domain methods and call commit once in the end of the request.
But in a distributed application, it isn't possible to use domain objects directly, instead a WCF service must receive a DTO.
Now my question is: how do you design the methods ChangeEmail and ChangeAddress for a distributed scenario? Each one must be a distinct operation in the Web service? If so, then when a user changes his email AND his address must be necessary to call two times to the service. Or instead I must model a web service like this:

var userDTO = _wcfService.GetUserDTOById(1);
userDTO.Email = "[email protected]";
userDTO.Street = "My new street";
userDTO.StreetNumber = "21";
_wcfService.PersistChanges(userDTO);
asked Feb 7, 2014 at 17:58
6
  • The second option you have mentioned is good. You can create a method to save an entity as a whole instead of putting them separately. So you can create a method "PersistChanges" in webservice to receive the object and save. Commented Feb 7, 2014 at 18:24
  • Now I realized what is my dilemma: DDD says you must have domain methods pertaining to a single use case. From this point of view,ChangeEmail and ChangeAddress must be distinct operations because they belongs to different use cases. I.e., the user probably doesn't change his email for the same reasons that he changes his address. Commented Feb 7, 2014 at 18:50
  • Changing a username or address cannot be considered as use case. Instead you can consider a business scenario as use case. For example "if a user is from a particular state then he must have a certain tax percentage" - this can be considered as a use case. Commented Feb 7, 2014 at 19:29
  • OK, let's say you have a method in your domain object named MakeUserPreferred() wich changes the state of the user and thus let us know that certain tax percentage must be applied. You would expose a MakeUserPreferred method in your web service? Or instead you set the DTO property ´UserDTO.IsPreferred = true´ and then call the service method ´_service.PersistChanges(userDTO)´?. Commented Feb 7, 2014 at 20:14
  • Can not you build a domain User object from the retrieved DTO? In this way, you could still call ChangeEmail and/or ChangeAddress methods, and then commit the changes. Both building the domain object from a DTO and committing changes to persistent storage should be responsibilities of a UserRepository. Commented Feb 12, 2014 at 11:05

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.