diff --git a/common/ASC.Core.Common/Context/WorkContext.cs b/common/ASC.Core.Common/Context/WorkContext.cs index 43294bcbe4..8f5cf918f4 100644 --- a/common/ASC.Core.Common/Context/WorkContext.cs +++ b/common/ASC.Core.Common/Context/WorkContext.cs @@ -150,10 +150,10 @@ public class WorkContext emailSender.Init(properties); } - NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyEMailSenderSysName, new EmailSenderSink(emailSender, _serviceProvider)); - NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyMessengerSenderSysName, new JabberSenderSink(jabberSender, _serviceProvider)); - NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyTelegramSenderSysName, new TelegramSenderSink(telegramSender, _serviceProvider)); - NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyPushSenderSysName, new PushSenderSink(pushSender, _serviceProvider)); + NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyEMailSenderSysName, new EmailSenderSink(emailSender)); + NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyMessengerSenderSysName, new JabberSenderSink(jabberSender)); + NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyTelegramSenderSysName, new TelegramSenderSink(telegramSender)); + NotifyContext.RegisterSender(_dispatchEngine, Constants.NotifyPushSenderSysName, new PushSenderSink(pushSender)); NotifyEngine.AddAction(); diff --git a/common/ASC.Core.Common/Notify/Channels/ISenderChannel.cs b/common/ASC.Core.Common/Notify/Channels/ISenderChannel.cs index 4e8c030265..5febd0ff3a 100644 --- a/common/ASC.Core.Common/Notify/Channels/ISenderChannel.cs +++ b/common/ASC.Core.Common/Notify/Channels/ISenderChannel.cs @@ -29,6 +29,6 @@ namespace ASC.Notify.Channels; public interface ISenderChannel { string SenderName { get; } - Task DirectSend(INoticeMessage message); - Task SendAsync(INoticeMessage message); + Task DirectSend(INoticeMessage message, IServiceScope serviceScope); + Task SendAsync(INoticeMessage message, IServiceScope serviceScope); } diff --git a/common/ASC.Core.Common/Notify/Channels/SenderChannel.cs b/common/ASC.Core.Common/Notify/Channels/SenderChannel.cs index 9d68f6c8a1..b00d1733f9 100644 --- a/common/ASC.Core.Common/Notify/Channels/SenderChannel.cs +++ b/common/ASC.Core.Common/Notify/Channels/SenderChannel.cs @@ -45,16 +45,16 @@ public class SenderChannel : ISenderChannel _firstSink = AddSink(_firstSink, dispatcherSink); } - public async Task SendAsync(INoticeMessage message) + public async Task SendAsync(INoticeMessage message, IServiceScope serviceScope) { ArgumentNullException.ThrowIfNull(message); - await _firstSink.ProcessMessageAsync(message); + await _firstSink.ProcessMessageAsync(message, serviceScope); } - public async Task DirectSend(INoticeMessage message) + public async Task DirectSend(INoticeMessage message, IServiceScope serviceScope) { - return await _senderSink.ProcessMessage(message); + return await _senderSink.ProcessMessage(message, serviceScope); } private ISink AddSink(ISink firstSink, ISink addedSink) diff --git a/common/ASC.Core.Common/Notify/EmailSenderSink.cs b/common/ASC.Core.Common/Notify/EmailSenderSink.cs index 34f0d6931f..64ea09e5af 100644 --- a/common/ASC.Core.Common/Notify/EmailSenderSink.cs +++ b/common/ASC.Core.Common/Notify/EmailSenderSink.cs @@ -29,16 +29,14 @@ namespace ASC.Core.Notify; public class EmailSenderSink : Sink { private static readonly string _senderName = Configuration.Constants.NotifyEMailSenderSysName; - private readonly INotifySender _sender; - private readonly IServiceProvider _serviceProvider; + private readonly INotifySender _sender; - public EmailSenderSink(INotifySender sender, IServiceProvider serviceProvider) + public EmailSenderSink(INotifySender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); - _serviceProvider = serviceProvider; } - public override async Task ProcessMessage(INoticeMessage message) + public override async Task ProcessMessage(INoticeMessage message, IServiceScope scope) { if (message.Recipient.Addresses == null || message.Recipient.Addresses.Length == 0) { @@ -48,7 +46,6 @@ public class EmailSenderSink : Sink var responce = new SendResponse(message, _senderName, default(SendResult)); try { - await using var scope = _serviceProvider.CreateAsyncScope(); var m = scope.ServiceProvider.GetRequiredService().CreateNotifyMessage(message, _senderName); var result = await _sender.Send(m); diff --git a/common/ASC.Core.Common/Notify/Engine/DispatchEngine.cs b/common/ASC.Core.Common/Notify/Engine/DispatchEngine.cs index 1c75a09765..f308524fd0 100644 --- a/common/ASC.Core.Common/Notify/Engine/DispatchEngine.cs +++ b/common/ASC.Core.Common/Notify/Engine/DispatchEngine.cs @@ -43,7 +43,7 @@ public class DispatchEngine _logger.LogOnly(_logOnly); } - public async Task Dispatch(INoticeMessage message, string senderName) + public async Task Dispatch(INoticeMessage message, string senderName, IServiceScope serviceScope) { var response = new SendResponse(message, senderName, SendResult.OK); if (!_logOnly) @@ -51,7 +51,7 @@ public class DispatchEngine var sender = _context.GetSender(senderName); if (sender != null) { - response = await sender.DirectSend(message); + response = await sender.DirectSend(message, serviceScope); } else { diff --git a/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs b/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs index 172115bf95..48eaed9de9 100644 --- a/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs +++ b/common/ASC.Core.Common/Notify/Engine/NotifyEngine.cs @@ -437,7 +437,7 @@ public class NotifyEngine : INotifyEngine, IDisposable return preventresponse; } - await channel.SendAsync(noticeMessage); + await channel.SendAsync(noticeMessage, serviceScope); return new SendResponse(noticeMessage, channel.SenderName, SendResult.Inprogress); } diff --git a/common/ASC.Core.Common/Notify/JabberSenderSink.cs b/common/ASC.Core.Common/Notify/JabberSenderSink.cs index a7d2266a67..99113e203d 100644 --- a/common/ASC.Core.Common/Notify/JabberSenderSink.cs +++ b/common/ASC.Core.Common/Notify/JabberSenderSink.cs @@ -31,20 +31,18 @@ class JabberSenderSink : Sink private static readonly string _senderName = Configuration.Constants.NotifyMessengerSenderSysName; private readonly INotifySender _sender; - public JabberSenderSink(INotifySender sender, IServiceProvider serviceProvider) + public JabberSenderSink(INotifySender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); - _serviceProvider = serviceProvider; } private readonly IServiceProvider _serviceProvider; - public override async Task ProcessMessage(INoticeMessage message) + public override async Task ProcessMessage(INoticeMessage message, IServiceScope scope) { try { var result = SendResult.OK; - await using var scope = _serviceProvider.CreateAsyncScope(); var m = scope.ServiceProvider.GetRequiredService().CreateNotifyMessage(message, _senderName); if (string.IsNullOrEmpty(m.Reciever)) diff --git a/common/ASC.Core.Common/Notify/PushSenderSink.cs b/common/ASC.Core.Common/Notify/PushSenderSink.cs index 3469f7c8be..2087cb57d9 100644 --- a/common/ASC.Core.Common/Notify/PushSenderSink.cs +++ b/common/ASC.Core.Common/Notify/PushSenderSink.cs @@ -35,22 +35,17 @@ class PushSenderSink : Sink private static readonly string _senderName = Constants.NotifyPushSenderSysName; private readonly INotifySender _sender; - public PushSenderSink(INotifySender sender, IServiceProvider serviceProvider) + public PushSenderSink(INotifySender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); - _serviceProvider = serviceProvider; } - private readonly IServiceProvider _serviceProvider; - - public override async Task ProcessMessage(INoticeMessage message) + public override async Task ProcessMessage(INoticeMessage message, IServiceScope scope) { try { var result = SendResult.OK; - await using var scope = _serviceProvider.CreateAsyncScope(); - var m = scope.ServiceProvider.GetRequiredService().CreateNotifyMessage(message, _senderName); if (string.IsNullOrEmpty(m.Reciever)) { @@ -100,7 +95,7 @@ public class PushSenderSinkMessageCreator : SinkMessageCreator { _tenantManager.SetCurrentTenant(Tenant.DefaultTenant); tenant = _tenantManager.GetCurrentTenant(false); - } + } var user = _userManager.GetUsers(new Guid(message.Recipient.ID)); var username = user.UserName; diff --git a/common/ASC.Core.Common/Notify/Sinks/DispatchSink.cs b/common/ASC.Core.Common/Notify/Sinks/DispatchSink.cs index 8c1e1d6098..be8c8f7eb6 100644 --- a/common/ASC.Core.Common/Notify/Sinks/DispatchSink.cs +++ b/common/ASC.Core.Common/Notify/Sinks/DispatchSink.cs @@ -37,13 +37,13 @@ class DispatchSink : Sink _senderName = senderName; } - public override Task ProcessMessage(INoticeMessage message) + public override Task ProcessMessage(INoticeMessage message, IServiceScope serviceScope) { - return _dispatcher.Dispatch(message, _senderName); + return _dispatcher.Dispatch(message, _senderName, serviceScope); } - public override async Task ProcessMessageAsync(INoticeMessage message) + public override async Task ProcessMessageAsync(INoticeMessage message, IServiceScope serviceScope) { - await _dispatcher.Dispatch(message, _senderName); + await _dispatcher.Dispatch(message, _senderName, serviceScope); } } diff --git a/common/ASC.Core.Common/Notify/Sinks/ISink.cs b/common/ASC.Core.Common/Notify/Sinks/ISink.cs index ffb68fdbb7..dd48fe62e4 100644 --- a/common/ASC.Core.Common/Notify/Sinks/ISink.cs +++ b/common/ASC.Core.Common/Notify/Sinks/ISink.cs @@ -29,6 +29,6 @@ namespace ASC.Notify.Sinks; public interface ISink { ISink NextSink { get; set; } - Task ProcessMessage(INoticeMessage message); - Task ProcessMessageAsync(INoticeMessage message); + Task ProcessMessage(INoticeMessage message, IServiceScope serviceScope); + Task ProcessMessageAsync(INoticeMessage message, IServiceScope serviceScope); } diff --git a/common/ASC.Core.Common/Notify/Sinks/Sink.cs b/common/ASC.Core.Common/Notify/Sinks/Sink.cs index c77a456f8b..8a08ee14ce 100644 --- a/common/ASC.Core.Common/Notify/Sinks/Sink.cs +++ b/common/ASC.Core.Common/Notify/Sinks/Sink.cs @@ -35,10 +35,10 @@ public abstract class Sink : ISink { public ISink NextSink { get; set; } - public abstract Task ProcessMessage(INoticeMessage message); + public abstract Task ProcessMessage(INoticeMessage message, IServiceScope serviceScope); - public virtual async Task ProcessMessageAsync(INoticeMessage message) + public virtual async Task ProcessMessageAsync(INoticeMessage message, IServiceScope serviceScope) { - await NextSink.ProcessMessageAsync(message); + await NextSink.ProcessMessageAsync(message, serviceScope); } } diff --git a/common/ASC.Core.Common/Notify/Telegram/TelegramSenderSink.cs b/common/ASC.Core.Common/Notify/Telegram/TelegramSenderSink.cs index b7f0e9f3e0..d833fafeb0 100644 --- a/common/ASC.Core.Common/Notify/Telegram/TelegramSenderSink.cs +++ b/common/ASC.Core.Common/Notify/Telegram/TelegramSenderSink.cs @@ -32,20 +32,18 @@ class TelegramSenderSink : Sink private readonly INotifySender _sender; private readonly IServiceProvider _serviceProvider; - public TelegramSenderSink(INotifySender sender, IServiceProvider serviceProvider) + public TelegramSenderSink(INotifySender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); - _serviceProvider = serviceProvider; } - public override async Task ProcessMessage(INoticeMessage message) + public override async Task ProcessMessage(INoticeMessage message, IServiceScope scope) { try { const SendResult result = SendResult.OK; - await using var scope = _serviceProvider.CreateAsyncScope(); var m = scope.ServiceProvider.GetRequiredService().CreateNotifyMessage(message, _senderName); await _sender.Send(m);