question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way of adding items to DomainEvents in AggregateRoot, which are triggered after UOW succeed

See original GitHub issue

for code in AbpDbContext

https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.EntityFramework/EntityFramework/AbpDbContext.cs#L282

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:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hikalkancommented, Nov 17, 2016

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.

0reactions
personballcommented, Dec 28, 2016

Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found