Provide a way of adding items to DomainEvents in AggregateRoot, which are triggered after UOW succeed
See original GitHub issuefor code in AbpDbContext
foreach (var domainEvent in domainEvents)
{
EventBus.Trigger(domainEvent.GetType(), entityAsObj, domainEvent);
}
Maybe it’s better as below
foreach (var domainEvent in domainEvents)
{
if (domainEvent is IShouldTriggerAfterUowCompleted)
{
CurrentUnitOfWorkProvider.Current.Completed += (sender, arg) =>
EventBus.Trigger(domainEvent.GetType(), entityAsObj, domainEvent);
}
else
{
EventBus.Trigger(domainEvent.GetType(), entityAsObj, domainEvent);
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Where to raise persistence-dependent domain events
My solution is that you raise events in both Domain layer and service layer. Your domain: public class Order { public void ...
Read more >Domain events: Design and implementation
When you want to raise an event, you just add it to the event collection from code at any method of the aggregate-root...
Read more >DDD aggregates and @DomainEvents
A method annotated with @DomainEvents is automatically invoked by Spring Data whenever an entity is saved using the right repository.
Read more >Decoupling Logic with Domain Events [Guide]
In this article, we'll walk through the process of using Domain Events to clean up how we decouple complex domain logic across the ......
Read more >Use domain events in Microservices | by Mina Ayoub
If JTA is not your option, then consider the way the event table is used. This method first saves the event to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for your suggestion.
Currently, ABP triggers events inside UOW. So, if an event throws exception, UOW will be reverted. Your suggestion provides a way of triggering events after UOW, so they will not be a part of the current UOW (transaction).
But this suggestion does not provide a way of using same event sometime in UOW, sometime after UOW. What about my suggestion:
In the AggregateRoot, we overload DomainEvents.Add() method, so it takes a boolean/enum parameter to trigger it after uow or inside uow. Default will be in UOW.
Thanks!