I'm doing some asp.net mvc coding using DDD. I have objects representing the business entities and service repositories that handle fetching and adding them. I'm new to this and as my application grows I begin to see a lot of secondary code that must run as a result of adding, deleting or changing my domain objects/data.
I'd like to make an event driven system where one action triggers other parts of code to run. For instance when I delete a user I want to be able to subscribe a number of other things to this action so they all are run when a delete takes place.
How have you coded your applications to handle these situations? How can I establish a reliable and coherent OO system for my problem? I already know about events and delegates but I'm more interested in coding techniques and nice practices.
Thing You might want to check out are so called domain events. Basically idea is that domain model itself triggers domain specific events (e.g. CustomerRegistered
) and pretty much anything You like can subscribe to them to do additional stuff outside of domain.
Udi Dahan wrote some nice articles on this: 1st, 2nd, 3rd.
Also - sample application by Szymon is quite explanatory on this.
CQRS is great, but it affects whole architecture. Might be an overkill.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With