当前 UoW 事务成功完成后,如何发布自定义事件?

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

有像EntityCreatedEventData这样的预定义事件在事务成功提交后发布。

我想在交易成功提交后发布自定义 Event。当前的 API?

可能吗?

是的,当前的 API。

来自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());
});

这与用于 EntityCreatedEventData 的 API 相同。