refactor(DIExtensions): Hinzufügen einer bedingten NET/NETFRAMEWORK-Unterstützung in DIExtensions
- Umschlossene Repository- und Executor-Registrierungen mit `#if NET`, um die Kompatibilität zwischen .NET und .NET Framework sicherzustellen - Hinzufügen des Abschnitts `#elif NETFRAMEWORK` für frameworkspezifische Importe - Verschieben der SQLExecutor- und Dapper-Typzuordnung unter bedingte Kompilierung - Anpassen der Methodensignaturen zur Unterstützung bedingter nullbarer Parameter
This commit is contained in:
parent
12063f36de
commit
9c867ac8aa
@ -1,23 +1,27 @@
|
||||
using EnvelopeGenerator.Infrastructure.Repositories;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using EnvelopeGenerator.Infrastructure.Executor;
|
||||
using Dapper;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
using DigitalData.UserManager.Domain.Entities;
|
||||
#if NET
|
||||
using EnvelopeGenerator.Infrastructure.Repositories;
|
||||
using EnvelopeGenerator.Infrastructure.Executor;
|
||||
using EnvelopeGenerator.Application.Common.Interfaces.Repositories;
|
||||
using EnvelopeGenerator.Application.Common.Interfaces.SQLExecutor;
|
||||
using DigitalData.EmailProfilerDispatcher.Abstraction.Entities;
|
||||
#elif NETFRAMEWORK
|
||||
using System;
|
||||
#endif
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure;
|
||||
|
||||
public static class DIExtensions
|
||||
namespace EnvelopeGenerator.Infrastructure
|
||||
{
|
||||
public static class DIExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the required repositories for the Envelope Generator service to the given <see cref="IServiceCollection"/>.
|
||||
/// This method adds the repositories for various envelope-related entities, such as configuration, document receivers, envelopes, and users,
|
||||
@ -34,13 +38,21 @@ public static class DIExtensions
|
||||
/// </remarks>
|
||||
[Obsolete("Use IRepository")]
|
||||
public static IServiceCollection AddEnvelopeGeneratorInfrastructureServices(this IServiceCollection services,
|
||||
Action<IServiceProvider, DbContextOptionsBuilder>? dbContextOptions = null,
|
||||
IConfiguration? sqlExecutorConfiguration = null,
|
||||
Action<SQLExecutorParams>? sqlExecutorConfigureOptions = null)
|
||||
Action<IServiceProvider, DbContextOptionsBuilder>
|
||||
#if NET
|
||||
?
|
||||
#endif
|
||||
dbContextOptions = null
|
||||
#if NET
|
||||
, IConfiguration? sqlExecutorConfiguration = null,
|
||||
Action<SQLExecutorParams>? sqlExecutorConfigureOptions = null
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if(dbContextOptions is not null)
|
||||
if (dbContextOptions != null)
|
||||
services.AddDbContext<EGDbContext>(dbContextOptions);
|
||||
|
||||
#if NET
|
||||
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
||||
services.TryAddScoped<IDocumentReceiverElementRepository, DocumentReceiverElementRepository>();
|
||||
services.TryAddScoped<IEnvelopeDocumentRepository, EnvelopeDocumentRepository>();
|
||||
@ -53,6 +65,7 @@ public static class DIExtensions
|
||||
services.TryAddScoped<IEnvelopeTypeRepository, EnvelopeTypeRepository>();
|
||||
services.TryAddScoped<IReceiverRepository, ReceiverRepository>();
|
||||
services.TryAddScoped<IEnvelopeReceiverReadOnlyRepository, EnvelopeReceiverReadOnlyRepository>();
|
||||
#endif
|
||||
|
||||
services.AddDbRepository(opt =>
|
||||
{
|
||||
@ -62,10 +75,13 @@ public static class DIExtensions
|
||||
// scan UserManager
|
||||
opt.RegisterFromAssembly<EGDbContext>(typeof(User).Assembly);
|
||||
|
||||
#if NET
|
||||
// scan EmailProfilerDispatcher
|
||||
opt.RegisterFromAssembly<EGDbContext>(typeof(EmailOut).Assembly);
|
||||
#endif
|
||||
});
|
||||
|
||||
#if NET
|
||||
services.AddSQLExecutor<Envelope>();
|
||||
services.AddSQLExecutor<Receiver>();
|
||||
services.AddSQLExecutor<Document>();
|
||||
@ -85,19 +101,21 @@ public static class DIExtensions
|
||||
|
||||
if (sqlExecutorConfiguration is not null || sqlExecutorConfigureOptions is not null)
|
||||
services.AddSQLExecutor(sqlExecutorConfiguration, sqlExecutorConfigureOptions);
|
||||
#endif
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
#if NET
|
||||
public static IServiceCollection AddSQLExecutor(this IServiceCollection services, IConfiguration? configuration = null, Action<SQLExecutorParams>? configureOptions = null)
|
||||
{
|
||||
if(configuration is not null && configureOptions is not null)
|
||||
if (configuration is not null && configureOptions is not null)
|
||||
throw new InvalidOperationException("Cannot use both 'configuration' and 'configureOptions'. Only one should be provided.");
|
||||
|
||||
if (configuration is not null)
|
||||
services.Configure<SQLExecutorParams>(configuration);
|
||||
|
||||
if(configureOptions is not null)
|
||||
if (configureOptions is not null)
|
||||
services.Configure(configureOptions);
|
||||
|
||||
return services.AddSingleton<ISQLExecutor, SQLExecutor>();
|
||||
@ -154,4 +172,6 @@ public static class DIExtensions
|
||||
|
||||
return services;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user