dimitrov333
dimitrov333

Reputation: 3

How do I publish a custom event after the current UoW transaction is successfully completed?

There are predefined events like EntityCreatedEventData that are published after the transaction is successfully committed.

I would like to publish a custom Event after the transaction is successfully committed. Is that possible with the current API?

Upvotes: 0

Views: 326

Answers (1)

aaron
aaron

Reputation: 43098

Yes, that is possible with the current API.

From https://docs.abp.io/en/abp/latest/Unit-Of-Work#other-iunitofwork-properties-methods:

  • OnCompleted method gets a callback action which is called when the unit of work successfully completed (where you can be sure that all changes are saved).
var uow = _unitOfWorkManager.Current;
uow.OnCompleted(() =>
{
    await _eventBus.PublishAsync(new MyCustomEvent());
});

This is the same API that is used for EntityCreatedEventData.

Upvotes: 3

Related Questions