Refactor DI and update dependencies

- Enhanced `AddAutoMapper` configuration for flexibility.
- Replaced `IEnvelopeMailService` with `IEnvelopeNotificationService`.
- Migrated from `IUserRepository` to `EGDbContext` for data access.
- Updated RabbitMQ configuration to use `AddMessagingServiceHttpClient`.
- Removed `AddUserManager` and `AddDispatcher` registrations.
- Added conditional `FluentValidation` dependencies for target frameworks.
- Upgraded `MediatR` to 14.2.0 and `AutoMapper` to 16.2.0.
- Added `HtmlSanitizer` dependency.
- Improved error handling and logging in `ReadOnlyController`.
This commit is contained in:
2026-11-17 20:09:23 +01:00
parent 6eb92a31a6
commit 224d029c18
6 changed files with 47 additions and 45 deletions

View File

@@ -1,6 +1,7 @@
using DigitalData.Core.Abstraction.Application.DTO;
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiverReadOnly;
using EnvelopeGenerator.Application.Common.Interfaces.Services;
using EnvelopeGenerator.Application.Common.Interfaces.Services.Notification;
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
using EnvelopeGenerator.Domain.Constants;
using MediatR;
@@ -20,17 +21,17 @@ public class ReadOnlyController : ControllerBase
{
private readonly ILogger<ReadOnlyController> _logger;
private readonly IEnvelopeReceiverReadOnlyService _readOnlyService;
private readonly IEnvelopeMailService _mailService;
private readonly IEnvelopeNotificationService _notificationService;
private readonly IEnvelopeHistoryService _historyService;
/// <summary>
/// Initializes a new instance of the <see cref="ReadOnlyController"/> class.
/// </summary>
public ReadOnlyController(ILogger<ReadOnlyController> logger, IEnvelopeReceiverReadOnlyService readOnlyService, IEnvelopeMailService mailService, IEnvelopeHistoryService historyService)
public ReadOnlyController(ILogger<ReadOnlyController> logger, IEnvelopeReceiverReadOnlyService readOnlyService, IEnvelopeNotificationService notificationService, IEnvelopeHistoryService historyService)
{
_logger = logger;
_readOnlyService = readOnlyService;
_mailService = mailService;
_notificationService = notificationService;
_historyService = historyService;
}
@@ -84,22 +85,23 @@ public class ReadOnlyController : ControllerBase
var newReadOnly = readRes.Data;
return await _mailService.SendAsync(newReadOnly).ThenAsync<int, IActionResult>(SuccessAsync: async _ =>
var notification = new DocumentSharedNotification
{
var histRes = await _historyService.RecordAsync((int)createDto.EnvelopeId, createDto.AddedWho, EnvelopeStatus.EnvelopeShared);
if (histRes.IsFailed)
{
_logger.LogError("Although the envelope was sent as read-only, the EnvelopeShared history could not be saved. Create DTO:\n{createDto}", JsonConvert.SerializeObject(createDto));
_logger.LogNotice(histRes.Notices);
}
DocumentTitle = newReadOnly.Envelope?.Title ?? string.Empty,
NameReceiver = newReadOnly.Receiver?.LastUsedName ?? string.Empty,
Origin = new Uri($"{Request.Scheme}://{Request.Host}"),
ReadOnlyId = newReadOnly.Id
};
return Ok();
},
await _notificationService.Notify(newReadOnly.ReceiverMail, notification, cancel);
Fail: (msg, ntc) =>
var histRes = await _historyService.RecordAsync((int)createDto.EnvelopeId, createDto.AddedWho, EnvelopeStatus.EnvelopeShared);
if (histRes.IsFailed)
{
_logger.LogNotice(ntc);
return StatusCode(StatusCodes.Status500InternalServerError);
});
_logger.LogError("Although the envelope was sent as read-only, the EnvelopeShared history could not be saved. Create DTO:\n{createDto}", JsonConvert.SerializeObject(createDto));
_logger.LogNotice(histRes.Notices);
}
return Ok();
}
}

View File

@@ -5,8 +5,6 @@ using DigitalData.Core.Abstractions;
using DigitalData.Core.Abstractions.Security.Extensions;
using DigitalData.Core.API;
using DigitalData.Core.Application;
using DigitalData.EmailProfilerDispatcher;
using DigitalData.UserManager.DependencyInjection;
using EnvelopeGenerator.Application;
using EnvelopeGenerator.Application.Common.Interfaces;
using EnvelopeGenerator.Application.Common.Interfaces.Doc;
@@ -288,11 +286,6 @@ try
.AddAuthenticationSchemes(AuthScheme.Sender, AuthScheme.Receiver)
.RequireAuthenticatedUser());
// User Manager
#pragma warning disable CS0618
builder.Services.AddUserManager<EGDbContext>();
#pragma warning restore CS0618
// LDAP Directory Search
builder.ConfigureBySection<DirectorySearchOptions>();
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
@@ -335,8 +328,6 @@ try
.AddNotificationInfrastructure(config);
#pragma warning restore CS0618
builder.Services.AddDispatcher<EGDbContext>();
// User Preferences (theme, dark mode, grid layouts — stored in TBDD_CACHE)
// Registration handled by Infrastructure DependencyInjection (AddEnvelopeGeneratorInfrastructureServices)
@@ -367,7 +358,6 @@ try
builder.Services.AddScoped<SignatureCacheService>();
builder.Services.AddDocInfrastructure();
builder.Services.AddCryptInfrastructure(config);
builder.Services.AddScoped<EnvelopeGenerator.Application.Common.Interfaces.Services.IEnvelopeMailService, EnvelopeGenerator.Application.Services.EnvelopeMailService>();
builder.Services.AddSingleton<AppVersionService>();
// EnvelopeService with HttpClient factory (for SSR scenarios)