当前 UoW 正确完成后,如何触发 EventBus?
How can I trigger the EventBus after the current UoW has properly completed?
如何在当前 UoW 正确完成后 Trigger
EventBus
?
在屏幕截图中,我触发了 EventBus
,这反过来告诉 SignalR 集线器告诉我的前端用户刷新缓存(重新 get
一些数据改变了)。
根据速度的不同,前端有时会因为过早请求而得不到更新的数据。我想确保 Trigger
仅在更改保存到数据库后发生。
这可能吗?
https://aspnetboilerplate.com/Pages/Documents/EventBus-Domain-Events#entity-changes
还有,我不想写后台作业,因为太慢了。
解决方案是使用内置的,未记录的:
await _backgroundJobManager.EnqueueEventAsync( new XXXXEventData());
是的,当前的 API 是可能的。
来自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())
};
这与用于 EntityCreatedEventData
的 API 相同。
如何在当前 UoW 正确完成后 Trigger
EventBus
?
在屏幕截图中,我触发了 EventBus
,这反过来告诉 SignalR 集线器告诉我的前端用户刷新缓存(重新 get
一些数据改变了)。
根据速度的不同,前端有时会因为过早请求而得不到更新的数据。我想确保 Trigger
仅在更改保存到数据库后发生。
这可能吗?
https://aspnetboilerplate.com/Pages/Documents/EventBus-Domain-Events#entity-changes
还有,我不想写后台作业,因为太慢了。
解决方案是使用内置的,未记录的:
await _backgroundJobManager.EnqueueEventAsync( new XXXXEventData());
是的,当前的 API 是可能的。
来自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())
};
这与用于 EntityCreatedEventData
的 API 相同。