.Net events vs DI event based approaches

I have been learning Domain Driven Design for a while and I came across several patterns along the way. One of them was domain events.

I decided to do a proof of concept of a micro-service using domain events.

In a nutshell, it works like this:

  • Automatically scan and register all event handlers on the .net core DI container at startup
  • Once a event is raised, I ask the DI container to resolve the associated handlers for me
  • Call the “HandleAsync” method of the handlers with Reflection

Everything works very well and it’s easy to add a new handler or a new event since everything is automated. It also provides a good separation of concerns.

To be honest, I followed this approach because it’s the one I see everyone using.

What about the native .net events? Could this be done with them? I’m sure it’s possible.

I’m just wondering why everyone is avoiding .net events when it comes to domain events or even mediator patterns with commands and queries.


submitted by /u/sparcopt
[link] [comments]

Leave a Reply