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. Is posible to call multiple domain methods and call commit once in the end of the request.
But in a distributed application isn't posible to use domain objects directly, instead a WCF service must receive a DTO.
Now my question is: how 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 necesary 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)
ChangeEmail
andChangeAddress
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. – Apocatastasis Feb 7 '14 at 18:50User
object from the retrieved DTO? In this way, you could still callChangeEmail
and/orChangeAddress
methods, and then commit the changes. Both building the domain object from a DTO and committing changes to persistent storage should be responsibilities of aUserRepository
. – rucamzu Feb 12 '14 at 11:05