Refactor handlers to use IOptionsMonitor for SQL options

Refactored Delete, Insert, and Update procedure handlers to inject IOptionsMonitor<SqlExceptionOptions> instead of SqlExceptionOptions, enabling dynamic configuration updates. Updated all references to use CurrentValue. Added necessary using directives and cleaned up redundant usings in InsertObjectProcedure.cs.
This commit is contained in:
2026-01-22 09:21:39 +01:00
parent d8e08b237d
commit e782eab62a
3 changed files with 11 additions and 8 deletions

View File

@@ -2,6 +2,7 @@ using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Options;
@@ -49,7 +50,7 @@ public static class DeleteObjectProcedureExtensions
}
}
public class DeleteObjectProcedureHandler(IRepository repo, SqlExceptionOptions sqlExceptionOptions) : IRequestHandler<DeleteObjectProcedure, int>
public class DeleteObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlExceptionOptions> sqlExOpt) : IRequestHandler<DeleteObjectProcedure, int>
{
public async Task<int> Handle(DeleteObjectProcedure request, CancellationToken cancel)
{
@@ -81,7 +82,7 @@ public class DeleteObjectProcedureHandler(IRepository repo, SqlExceptionOptions
}
catch (SqlException ex)
{
if (sqlExceptionOptions.SqlExceptionNumber.Contains(ex.Number))
if (sqlExOpt.CurrentValue.SqlExceptionNumber.Contains(ex.Number))
throw new BadRequestException(ex.Message, ex);
else
throw;

View File

@@ -2,13 +2,14 @@
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Options;
using ReC.Application.EndpointAuth.Commands;
using ReC.Application.EndpointParams.Commands;
using ReC.Application.Endpoints.Commands;
using ReC.Application.Results.Commands;
using ReC.Application.Profile.Commands;
using ReC.Application.Common.Options;
using ReC.Application.Results.Commands;
namespace ReC.Application.Common.Procedures.InsertProcedure;
@@ -43,7 +44,7 @@ public static class InsertObjectProcedureExtensions
}
}
public class InsertObjectProcedureHandler(IRepository repo, SqlExceptionOptions sqlExceptionOptions) : IRequestHandler<InsertObjectProcedure, long>
public class InsertObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlExceptionOptions> sqlExOpt) : IRequestHandler<InsertObjectProcedure, long>
{
public async Task<long> Handle(InsertObjectProcedure request, CancellationToken cancel)
{
@@ -129,7 +130,7 @@ public class InsertObjectProcedureHandler(IRepository repo, SqlExceptionOptions
}
catch (SqlException ex)
{
if (sqlExceptionOptions.SqlExceptionNumber.Contains(ex.Number))
if (sqlExOpt.CurrentValue.SqlExceptionNumber.Contains(ex.Number))
throw new BadRequestException(ex.Message, ex);
else
throw;

View File

@@ -2,6 +2,7 @@ using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Options;
using ReC.Application.EndpointAuth.Commands;
@@ -49,7 +50,7 @@ public static class UpdateObjectProcedureExtensions
}
}
public class UpdateObjectProcedureHandler(IRepository repo, SqlExceptionOptions sqlExceptionOptions) : IRequestHandler<UpdateObjectProcedure, int>
public class UpdateObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlExceptionOptions> sqlExOpt) : IRequestHandler<UpdateObjectProcedure, int>
{
public async Task<int> Handle(UpdateObjectProcedure request, CancellationToken cancel)
{
@@ -141,7 +142,7 @@ public class UpdateObjectProcedureHandler(IRepository repo, SqlExceptionOptions
}
catch (SqlException ex)
{
if (sqlExceptionOptions.SqlExceptionNumber.Contains(ex.Number))
if (sqlExOpt.CurrentValue.SqlExceptionNumber.Contains(ex.Number))
throw new BadRequestException(ex.Message, ex);
else
throw;