-1

I'm designing the base classes and I don't know if I should add the field 'domainEvents' to the Entity class or only to the AggregateRoot class.

I must add the code for add and remove events in Entity.cs or AggregateRoot.cs

private List<INotification> _domainEvents;
public IReadOnlyCollection<INotification> DomainEvents => _domainEvents;
public void AddDomainEvent(INotification eventItem) {}
public void RemoveDomainEvent(INotification eventItem) {}
  • 1
    can you add some details about what you are actually trying to accomplish? – Michael Sep 29 '18 at 14:18
  • @Michael I have edited the post. – Jhon Duck Sep 29 '18 at 14:32
  • 1
    ok.. but still. This could be a "customer relationship management" system. It could be a "game engine". You could be writing a device driver. You could be creating an SVG-to-WebGL-converter. It could be about a speech recognition software. – Michael Sep 29 '18 at 14:36
  • 2
    I agree with Michael. The goal is not necessarily to fulfill the tenets of DDD, it is to satisfy your specific software requirements. – Robert Harvey Sep 29 '18 at 15:11
  • 1
    The point of domain driven design is to focus on the domain, and make decisions based on that. If you cannot come up with a real example for a domain, you cannot do domain driven design. I would go even further than that: deciding what your project is all about should be the first decision for any project. - If you want to learn DDD, pick a domain first. Everything else will be a waste of your time. - I have done DDD for years, but I never heard of "aggregate roots"; I have used some "value objects", but having a file named "ValueObject.cs" feels wrong. – Michael Sep 30 '18 at 21:52
0

It all depends on your domain model and the purpose of these events.

Maybe it could make sense to add domain event to aggregate roots only, if the purpose is to handle events that affect the aggregate as a whole.

But maybe it could make sense to add them to relevant entity classes within the aggregate. Take the usual Car aggregate example, with Wheels and Engine being entities. It could then make sense to add events at entity level, to handle events that are related to the tire pressure or the engine temperature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.