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:
@@ -45,8 +45,10 @@ public static class DependencyInjection
|
|||||||
services.TryAddScoped<IEnvelopeReceiverReadOnlyService, EnvelopeReceiverReadOnlyService>();
|
services.TryAddScoped<IEnvelopeReceiverReadOnlyService, EnvelopeReceiverReadOnlyService>();
|
||||||
|
|
||||||
//Auto mapping profiles
|
//Auto mapping profiles
|
||||||
services.AddAutoMapper(Assembly.GetExecutingAssembly());
|
services.AddAutoMapper(
|
||||||
services.AddAutoMapper(typeof(DigitalData.UserManager.Application.DIExtensions));
|
_ => { },
|
||||||
|
Assembly.GetExecutingAssembly(),
|
||||||
|
typeof(DigitalData.UserManager.Application.DIExtensions).Assembly);
|
||||||
|
|
||||||
services.Configure<DispatcherParams>(config.GetSection(nameof(DispatcherParams)));
|
services.Configure<DispatcherParams>(config.GetSection(nameof(DispatcherParams)));
|
||||||
services.Configure<MailParams>(config.GetSection(nameof(MailParams)));
|
services.Configure<MailParams>(config.GetSection(nameof(MailParams)));
|
||||||
|
|||||||
@@ -20,10 +20,9 @@
|
|||||||
<PackageReference Include="DigitalData.Core.Client" Version="2.1.0" />
|
<PackageReference Include="DigitalData.Core.Client" Version="2.1.0" />
|
||||||
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
|
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
|
||||||
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="3.1.1" />
|
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="3.1.1" />
|
||||||
<PackageReference Include="FluentValidation" Version="11.11.0" />
|
|
||||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
|
|
||||||
<PackageReference Include="HtmlSanitizer" Version="9.0.892" />
|
<PackageReference Include="HtmlSanitizer" Version="9.0.892" />
|
||||||
<PackageReference Include="MediatR" Version="12.5.0" />
|
<PackageReference Include="MediatR" Version="14.2.0" />
|
||||||
<PackageReference Include="Microsoft.Identity.Client" Version="4.82.1" />
|
<PackageReference Include="Microsoft.Identity.Client" Version="4.82.1" />
|
||||||
<PackageReference Include="Otp.NET" Version="1.4.0" />
|
<PackageReference Include="Otp.NET" Version="1.4.0" />
|
||||||
<PackageReference Include="QRCoder" Version="1.6.0" />
|
<PackageReference Include="QRCoder" Version="1.6.0" />
|
||||||
@@ -36,14 +35,20 @@
|
|||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
|
<PackageReference Include="FluentValidation" Version="11.11.0" />
|
||||||
|
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||||
|
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
||||||
|
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
|
||||||
|
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
||||||
|
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -89,14 +94,14 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
|
||||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
<PackageReference Include="AutoMapper" Version="16.2.0" />
|
||||||
<PackageReference Include="CommandDotNet">
|
<PackageReference Include="CommandDotNet">
|
||||||
<Version>8.1.1</Version>
|
<Version>8.1.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
|
||||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
<PackageReference Include="AutoMapper" Version="16.2.0" />
|
||||||
<PackageReference Include="CommandDotNet">
|
<PackageReference Include="CommandDotNet">
|
||||||
<Version>8.1.1</Version>
|
<Version>8.1.1</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
@@ -31,12 +31,15 @@ public static class DependencyInjection
|
|||||||
$"MessagingServiceApiUrl must be provided when ClientType is set to Api in the '{sectionName}' configuration section.");
|
$"MessagingServiceApiUrl must be provided when ClientType is set to Api in the '{sectionName}' configuration section.");
|
||||||
break;
|
break;
|
||||||
case ConsumerType.RabbitMQ:
|
case ConsumerType.RabbitMQ:
|
||||||
if(options.RabbitMQ is not null)
|
if (options.ApiUrl is string rabbitModeApiUrl)
|
||||||
services.AddMessagingServiceClient(ntfConfiguration, nameof(options.RabbitMQ));
|
services.AddMessagingServiceHttpClient(opt =>
|
||||||
|
{
|
||||||
|
opt.BaseAddress = new Uri(rabbitModeApiUrl);
|
||||||
|
});
|
||||||
else
|
else
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
$"Missing RabbitMQ connection configuration." +
|
$"Missing API URL configuration." +
|
||||||
$"When ClientType is set to RabbitMQ, a valid RabbitMQ configuration must be provided in the '{sectionName}' configuration section.");
|
$"When ClientType is set to RabbitMQ in an isolated host, Notification:ApiUrl must be provided in the '{sectionName}' configuration section.");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#if NET
|
#if NET
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using DigitalData.UserManager.Application.Contracts.Repositories;
|
|
||||||
using EnvelopeGenerator.Application.Common.Interfaces.SQLExecutor;
|
using EnvelopeGenerator.Application.Common.Interfaces.SQLExecutor;
|
||||||
using EnvelopeGenerator.Application.Common.SQL;
|
using EnvelopeGenerator.Application.Common.SQL;
|
||||||
using EnvelopeGenerator.Domain.Entities;
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
@@ -12,13 +12,11 @@ namespace EnvelopeGenerator.Infrastructure.Executor;
|
|||||||
|
|
||||||
public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
||||||
{
|
{
|
||||||
[Obsolete("Use IRepository")]
|
private readonly EGDbContext _dbContext;
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
|
|
||||||
[Obsolete("Use IRepository")]
|
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, EGDbContext dbContext) : base(provider, sqlExecutorParamsOptions)
|
||||||
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IUserRepository userRepository) : base(provider, sqlExecutorParamsOptions)
|
|
||||||
{
|
{
|
||||||
_userRepository = userRepository;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("Use IRepository")]
|
[Obsolete("Use IRepository")]
|
||||||
@@ -33,9 +31,11 @@ public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
|||||||
?? throw new InvalidOperationException($"Envelope creation failed. Parameters:" +
|
?? throw new InvalidOperationException($"Envelope creation failed. Parameters:" +
|
||||||
$"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}.");
|
$"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}.");
|
||||||
|
|
||||||
envelope.User = await _userRepository.ReadByIdAsync(envelope.UserId);
|
envelope.User = await _dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(x => x.Id == envelope.UserId, cancellation);
|
||||||
|
|
||||||
return envelope;
|
return envelope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.DTO;
|
using DigitalData.Core.Abstraction.Application.DTO;
|
||||||
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiverReadOnly;
|
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiverReadOnly;
|
||||||
using EnvelopeGenerator.Application.Common.Interfaces.Services;
|
using EnvelopeGenerator.Application.Common.Interfaces.Services;
|
||||||
|
using EnvelopeGenerator.Application.Common.Interfaces.Services.Notification;
|
||||||
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
|
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
|
||||||
using EnvelopeGenerator.Domain.Constants;
|
using EnvelopeGenerator.Domain.Constants;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
@@ -20,17 +21,17 @@ public class ReadOnlyController : ControllerBase
|
|||||||
{
|
{
|
||||||
private readonly ILogger<ReadOnlyController> _logger;
|
private readonly ILogger<ReadOnlyController> _logger;
|
||||||
private readonly IEnvelopeReceiverReadOnlyService _readOnlyService;
|
private readonly IEnvelopeReceiverReadOnlyService _readOnlyService;
|
||||||
private readonly IEnvelopeMailService _mailService;
|
private readonly IEnvelopeNotificationService _notificationService;
|
||||||
private readonly IEnvelopeHistoryService _historyService;
|
private readonly IEnvelopeHistoryService _historyService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ReadOnlyController"/> class.
|
/// Initializes a new instance of the <see cref="ReadOnlyController"/> class.
|
||||||
/// </summary>
|
/// </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;
|
_logger = logger;
|
||||||
_readOnlyService = readOnlyService;
|
_readOnlyService = readOnlyService;
|
||||||
_mailService = mailService;
|
_notificationService = notificationService;
|
||||||
_historyService = historyService;
|
_historyService = historyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,22 +85,23 @@ public class ReadOnlyController : ControllerBase
|
|||||||
|
|
||||||
var newReadOnly = readRes.Data;
|
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);
|
DocumentTitle = newReadOnly.Envelope?.Title ?? string.Empty,
|
||||||
if (histRes.IsFailed)
|
NameReceiver = newReadOnly.Receiver?.LastUsedName ?? string.Empty,
|
||||||
{
|
Origin = new Uri($"{Request.Scheme}://{Request.Host}"),
|
||||||
_logger.LogError("Although the envelope was sent as read-only, the EnvelopeShared history could not be saved. Create DTO:\n{createDto}", JsonConvert.SerializeObject(createDto));
|
ReadOnlyId = newReadOnly.Id
|
||||||
_logger.LogNotice(histRes.Notices);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
_logger.LogError("Although the envelope was sent as read-only, the EnvelopeShared history could not be saved. Create DTO:\n{createDto}", JsonConvert.SerializeObject(createDto));
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError);
|
_logger.LogNotice(histRes.Notices);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ using DigitalData.Core.Abstractions;
|
|||||||
using DigitalData.Core.Abstractions.Security.Extensions;
|
using DigitalData.Core.Abstractions.Security.Extensions;
|
||||||
using DigitalData.Core.API;
|
using DigitalData.Core.API;
|
||||||
using DigitalData.Core.Application;
|
using DigitalData.Core.Application;
|
||||||
using DigitalData.EmailProfilerDispatcher;
|
|
||||||
using DigitalData.UserManager.DependencyInjection;
|
|
||||||
using EnvelopeGenerator.Application;
|
using EnvelopeGenerator.Application;
|
||||||
using EnvelopeGenerator.Application.Common.Interfaces;
|
using EnvelopeGenerator.Application.Common.Interfaces;
|
||||||
using EnvelopeGenerator.Application.Common.Interfaces.Doc;
|
using EnvelopeGenerator.Application.Common.Interfaces.Doc;
|
||||||
@@ -288,11 +286,6 @@ try
|
|||||||
.AddAuthenticationSchemes(AuthScheme.Sender, AuthScheme.Receiver)
|
.AddAuthenticationSchemes(AuthScheme.Sender, AuthScheme.Receiver)
|
||||||
.RequireAuthenticatedUser());
|
.RequireAuthenticatedUser());
|
||||||
|
|
||||||
// User Manager
|
|
||||||
#pragma warning disable CS0618
|
|
||||||
builder.Services.AddUserManager<EGDbContext>();
|
|
||||||
#pragma warning restore CS0618
|
|
||||||
|
|
||||||
// LDAP Directory Search
|
// LDAP Directory Search
|
||||||
builder.ConfigureBySection<DirectorySearchOptions>();
|
builder.ConfigureBySection<DirectorySearchOptions>();
|
||||||
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
|
builder.Services.AddDirectorySearchService(config.GetSection("DirectorySearchOptions"));
|
||||||
@@ -335,8 +328,6 @@ try
|
|||||||
.AddNotificationInfrastructure(config);
|
.AddNotificationInfrastructure(config);
|
||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
|
|
||||||
builder.Services.AddDispatcher<EGDbContext>();
|
|
||||||
|
|
||||||
// User Preferences (theme, dark mode, grid layouts — stored in TBDD_CACHE)
|
// User Preferences (theme, dark mode, grid layouts — stored in TBDD_CACHE)
|
||||||
// Registration handled by Infrastructure DependencyInjection (AddEnvelopeGeneratorInfrastructureServices)
|
// Registration handled by Infrastructure DependencyInjection (AddEnvelopeGeneratorInfrastructureServices)
|
||||||
|
|
||||||
@@ -367,7 +358,6 @@ try
|
|||||||
builder.Services.AddScoped<SignatureCacheService>();
|
builder.Services.AddScoped<SignatureCacheService>();
|
||||||
builder.Services.AddDocInfrastructure();
|
builder.Services.AddDocInfrastructure();
|
||||||
builder.Services.AddCryptInfrastructure(config);
|
builder.Services.AddCryptInfrastructure(config);
|
||||||
builder.Services.AddScoped<EnvelopeGenerator.Application.Common.Interfaces.Services.IEnvelopeMailService, EnvelopeGenerator.Application.Services.EnvelopeMailService>();
|
|
||||||
builder.Services.AddSingleton<AppVersionService>();
|
builder.Services.AddSingleton<AppVersionService>();
|
||||||
|
|
||||||
// EnvelopeService with HttpClient factory (for SSR scenarios)
|
// EnvelopeService with HttpClient factory (for SSR scenarios)
|
||||||
|
|||||||
Reference in New Issue
Block a user