Browse Source

feat(notifications): notification to be published at the end of the unit of work

pull/529/head
cKey 4 years ago
parent
commit
b7c092cacd
  1. 34
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDispatcher.cs
  2. 19
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs
  3. 2
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs

34
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDispatcher.cs

@ -1,34 +0,0 @@
using System;
using System.Threading.Tasks;
namespace LINGYUN.Abp.Notifications
{
/// <summary>
/// 通知发送者接口
/// </summary>
[Obsolete("Notification system redesigned, publisher interface deactivated, please use INotificationSender")]
public interface INotificationDispatcher
{
///// <summary>
///// 发送通知
///// </summary>
///// <param name="notificationName">通知名称</param>
///// <param name="data">数据</param>
///// <param name="tenantId">租户</param>
///// <param name="notificationSeverity">级别</param>
///// <returns></returns>
//Task DispatchAsync(NotificationName notificationName, NotificationData data, Guid? tenantId = null,
// NotificationSeverity notificationSeverity = NotificationSeverity.Info);
///// <summary>
///// 发送通知事件
///// </summary>
///// <param name="notificationName">通知名称</param>
///// <param name="data">数据</param>
///// <param name="tenantId">租户</param>
///// <param name="notificationSeverity">级别</param>
///// <returns></returns>
//Task DispatchEventAsync(NotificationName notificationName, NotificationData data, Guid? tenantId = null,
// NotificationSeverity notificationSeverity = NotificationSeverity.Info);
}
}

19
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs

@ -9,6 +9,7 @@ using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Uow;
namespace LINGYUN.Abp.Notifications
{
@ -30,16 +31,22 @@ namespace LINGYUN.Abp.Notifications
/// Reference to <see cref="IDistributedIdGenerator"/>.
/// </summary>
protected IDistributedIdGenerator DistributedIdGenerator { get; }
/// <summary>
/// Reference to <see cref="IUnitOfWorkManager"/>.
/// </summary>
protected IUnitOfWorkManager UnitOfWorkManager { get; }
protected AbpNotificationOptions Options { get; }
public NotificationSender(
IDistributedEventBus distributedEventBus,
IDistributedIdGenerator distributedIdGenerator,
IUnitOfWorkManager unitOfWorkManager,
IOptions<AbpNotificationOptions> options)
{
Options = options.Value;
DistributedEventBus = distributedEventBus;
DistributedIdGenerator = distributedIdGenerator;
UnitOfWorkManager = unitOfWorkManager;
Logger = NullLogger<NotificationSender>.Instance;
}
@ -88,7 +95,17 @@ namespace LINGYUN.Abp.Notifications
Severity = severity
};
await DistributedEventBus.PublishAsync(eto);
if (UnitOfWorkManager.Current != null)
{
UnitOfWorkManager.Current.OnCompleted(async () =>
{
await DistributedEventBus.PublishAsync(eto);
});
}
else
{
await DistributedEventBus.PublishAsync(eto);
}
return eto.Id.ToString();
}

2
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs

@ -39,7 +39,7 @@ namespace LINGYUN.Abp.Notifications
/// 如果指定了用户列表,应该在事件订阅程序中通过此集合过滤订阅用户<br/>
/// 如果未指定用户列表,应该在事件订阅程序中过滤所有订阅此通知的用户
/// </remarks>
public List<UserIdentifier> Users { get; set; }
public List<UserIdentifier> Users { get; set; } = new List<UserIdentifier>();
public NotificationEto() : base()
{
}

Loading…
Cancel
Save