4

What is the difference between using domain services and domain events? The thing I can see is that domain events allow you to further decouple your domain model and get away from using domain services. It seems the simple implementation would be to use a service and then eventually refactor to using domain events.

Additionally, it seems odd that when using Domain Events I have to wire them up in the Application Code (IOC container or with Poor Man’s DI). For example let’s say I have an Order Aggregate that calls OrderCreated which triggers an update to they Inventory System. From everything I’ve seen, I have to wire this event and event handler in application code. Again, domain services seem simpler and more encapsulated. Domain events do not seem adequate for domain-to-domain events but rather domain-to-application events.

Am I understanding this correctly or is there a much higher-level concept I'm missing?

2

I think you are looking at this with the wrong perspective. The two concepts are generally NOT mutually exclusive, they are typically two entirely different areas of your system. For instance, domain services are intended to contain your applications business logic and core functionality. While utilizing domain events is intended to function as the "service to service communication layer".

When you are using event based architectures, it is primarily intended to de-couple the producer from the consumer. In addition to this benefit you also gain the ability to publish a single event from some producer service, which may have any number of consumer services listening for the event. This allows you to substantially reduce the amount of messaging between related services, while also eliminating the need for methods such as server-side long pulling etc.

When you are designing an application, utilizing the event based architecture, you generally don't have much concern for what the exact implementation is of the event consumers. You just ensure that you have a well-defined event interface, which can then be consumed by a service written in any language, with any implementation type (could be a serverless function, megalithic application or microservice... it doesn't really matter!)

Hopefully this clears it up a bit for you :) If you still feel like you have a gap in your understanding, I would love to clarify any specific aspect of my answer!

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.