Gopal
Gopal

Reputation: 265

detect a change to domain object

There is an Entity:Customer and if the Customer changes his name ( via Web UI), the Customer Service must detect this change and send an email to Administrator.

Now should this responsibility be assigned to the Customer? Something like

c.HasChangedName(NewName); where c is a reference to the Customer

There could be other activities undertaken by the CustomerService based on such changes to the Customer entity. Email is just an example.

Upvotes: 1

Views: 128

Answers (1)

xelibrion
xelibrion

Reputation: 2234

By my opinion, Customer aggregate root (I suppose it is an aggregate root and not an entity) should publish CustomerNameChanged event in

customer.ChangeName(string newname) 

method call.

You could look at some implementation sample in Greg Young's github repository. Or if don't want to use event sourcing you could take a look at Udi Dahan's post about domain events

Upvotes: 4

Related Questions