[英]Asp.Net Boilerplate Entity notifications
我有在 .NET Core Web 应用程序中工作的通知。 但是我正在尝试了解实体通知操作。 当我阅读文档并尝试编写一些场景时,它似乎并没有像我想象的那样工作。 我的应用程序有一个“包裹”表。 我根据表中列出的包裹之一创建了订阅
await _notificationSubscriptionManager
.SubscribeAsync(new UserIdentifier(tenantId, userId), "ParcelTransfer", new EntityIdentifier(typeof(Parcel), 3041));
我使用的 Id 值是 Parcel 数据库表中一个 Parcel 的 Id 值。 然后代码会触发一个发布调用,但使用不同的 Parcel Id 值
await _notificationPublisher.PublishAsync(notificationName, data: new MessageNotificationData(message),
new EntityIdentifier(typeof(Parcel), 3042), userIds: userIds);
但是,我仍然收到通知。 我认为因为我使用不同的 Parcel Identity Id 值发出了 Publish 调用,所以不会发送通知。 我想我不明白这个过程是如何运作的。
弄清楚了。 我不需要在PublishAsync()
方法中指定EntityIdentifier
对象。 我只需要在Subscription SubscribeAsync()
方法中指定具有租户和UserId的用户这一事实。
在发布发布命令,代码只需要看看基于订阅名订阅。
我还必须将SendNotifications()
和SendNotificationsAsync()
两种方法的EmailRealTimeNotifier类修改为
[UnitOfWork]
public void SendNotifications(UserNotification[] userNotifications)
{
foreach (var userNotification in userNotifications)
{
if (userNotification.Notification.Data is MessageNotificationData data)
{
using (_unitOfWorkManager.Current.SetTenantId(userNotification.TenantId))
{
var user = _userManager.GetUserById(userNotification.UserId);
_emailSender.Send(
to: user.EmailAddress,
subject: "You have a new notification!",
body: data.Message,
isBodyHtml: true
);
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.