I have an ASP.NET MVC web site working in this way:
(In the controller)
var user = _applicationService.GetUserById(1);
user.ChangeEmail("mynemail@somewhere.com");
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 = "mynewemail@somewhere.com";
userDTO.Street = "My new street";
userDTO.StreetNumber = "21";
_wcfService.PersistChanges(userDTO);