How can I Trigger
the EventBus
after the current UoW has properly completed?
In the screenshot, I am triggering the EventBus
, which in turn is telling the SignalR hub to tell my front-end user to refresh a cache (re-get
some data that has changed).
Depending on speed, the front-end sometimes doesn't get the updated data because it requested it too early. I want to ensure the Trigger
only happens after the changes have been saved to the database.
Is this possible?
https://aspnetboilerplate.com/Pages/Documents/EventBus-Domain-Events#entity-changes
Also, I don't want to write a background job because it will be too slow.
Yes, that is possible with the current API.
From https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#events:
Events
A unit of work has the Completed, Failed and Disposed events. You can register to these events and perform any operations you need. For example, you may want to run some code when the current unit of work successfully completes.
var uow = _unitOfWorkManager.Current;
uow.Completed += (sender, args) =>
{
EventBus.Trigger(new MyCustomEventData())
};
This is the same API that is used for EntityCreatedEventData
.