Updating an Entity internal to an Aggregate

Say we have an Aggregate with Customer as the root and Address as an internal Entity (Addresses need to be distinguishable within the Customer Aggregate).

A common way of updating a particular Address for a Customer is

Customer customer = customerRepository.Find(id);
customer.UpdateAddress(addressId, addressData);

I can’t help but think this is a waste. Instead of getting the customer from the persistent storage and using it to update the address I want to update the address directly.

If I can grab hold of my UoW (NHibernate’s Session) I could just call session.Update(addressData) and that would be that (provided addressData has the id in it).

But NHibernate is hidden behind the repositories and I only have a repository for customer since it is the aggregate root. I would have to have the following in my CustomerRepository.


Internally this would call SaveOrUpdate on the Session.

The quetion is how many DDD rules am I breaking with this?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s