Hi,
There is something not clear to me about domain-driven-design and unit of work pattern. Let's say I have an entity that was retrieved from a repository. Once I updated this entity, how UnitOfWork should know that it was updated, so the updated entity can be persisted to the DB? Currently, I see two options:
1) Manually call uow.Update(entity) in the service layer. E.g.:
Employee emp = EmployeeRepository.GetByID(1);
emp.Name = "NewName";
uow.Update(emp);
uow.Commit();
2) Rely on some ORM magic to track changes, and persist updated entities to the DB. E.g.:
Employee emp = EmployeeRepository.GetByID(1);
emp.Name = "NewName";
uow.Commit();
Both these options seems hairy to me: First - if changes were made inside some aggregate, the aggregate should let the service layer know that it updated some entities. Second - isn't relying on ORM implementation is violation of Persistence Ignorance principle?
What do you do in your projects? Or maybe I miss something / messed up something and there is better solution?
Thanks