Refactor DI extensions and add SQL executor support

Removed `DIExtensions.cs` and integrated its content into `DependencyExtensions.cs`, enhancing the dependency injection setup with repository and SQL executor registrations. Added a new `CreateEnvelopeSQL` class implementing the `ISQL<Envelope>` interface, currently with a placeholder implementation.
This commit is contained in:
Developer 02 2025-05-05 00:31:58 +02:00
parent adbfd69418
commit 841da3c261
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,14 @@
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
using EnvelopeGenerator.Domain.Entities;
namespace EnvelopeGenerator.Application.Envelopes.Commands;
/// <summary>
///
/// </summary>
public class CreateEnvelopeSQL : ISQL<Envelope>
{
/// <summary>
///
/// </summary>
public string Raw => string.Empty;
}

View File

@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
using DigitalData.Core.Infrastructure; using DigitalData.Core.Infrastructure;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using DigitalData.Core.Infrastructure.AutoMapper; using DigitalData.Core.Infrastructure.AutoMapper;
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
namespace EnvelopeGenerator.Infrastructure; namespace EnvelopeGenerator.Infrastructure;
@ -59,6 +60,42 @@ public static class DIExtensions
services.AddDbRepository<EGDbContext, UserReceiver>(context => context.UserReceivers).UseAutoMapper(); services.AddDbRepository<EGDbContext, UserReceiver>(context => context.UserReceivers).UseAutoMapper();
services.AddDbRepository<EGDbContext, EnvelopeReceiverReadOnly>(context => context.EnvelopeReceiverReadOnlys).UseAutoMapper(); services.AddDbRepository<EGDbContext, EnvelopeReceiverReadOnly>(context => context.EnvelopeReceiverReadOnlys).UseAutoMapper();
services.AddSQLExecutor<Envelope>();
services.AddSQLExecutor<Receiver>();
services.AddSQLExecutor<EnvelopeDocument>();
services.AddSQLExecutor<DocumentReceiverElement>();
services.AddSQLExecutor<DocumentStatus>();
return services;
}
public static IServiceCollection AddSQLExecutor<T>(this IServiceCollection services) where T : class
{
services.AddSingleton<ISQLExecutor<T>, SQLExecutor<T>>();
var interfaceType = typeof(ISQL<>);
var targetGenericType = interfaceType.MakeGenericType(typeof(T));
var implementations = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(a =>
{
try { return a.GetTypes(); }
catch { return Array.Empty<Type>(); }
})
.Where(t =>
t is { IsClass: true, IsAbstract: false } &&
t.GetInterfaces().Any(i =>
i.IsGenericType &&
i.GetGenericTypeDefinition() == interfaceType &&
i.GenericTypeArguments[0] == typeof(T)
)
);
foreach (var impl in implementations)
{
services.AddSingleton(impl);
}
return services; return services;
} }
} }