TekH 1c90e693da Deprecate services in favor of MediatR integration
This commit introduces the `[Obsolete("Use MediatR")]` attribute to various service fields and methods across multiple controllers and extension classes, signaling a transition to MediatR for handling requests and commands.

Key changes include:
- Marking `IEnvelopeService`, `IEnvelopeReceiverService`, and `IEnvelopeTypeService` as obsolete in their respective controllers.
- Updating `AddEnvelopeGeneratorInfrastructureServices` to utilize `IRepository`.
- Refactoring `AddCommandManagerRunner` and `CreateHost` methods to indicate obsolescence.
- Replacing `DigitalData.Core.DTO` with `DigitalData.Core.Abstraction.Application.DTO` in using directives.

These changes modernize the codebase and improve command and query handling while cleaning up service dependencies.
2025-06-30 10:05:36 +02:00

42 lines
1.5 KiB
C#

using Microsoft.Extensions.Hosting;
using EnvelopeGenerator.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using EnvelopeGenerator.Application.Services;
using Microsoft.EntityFrameworkCore;
using EnvelopeGenerator.Application;
namespace EnvelopeGenerator.Tests.Application;
public class Mock
{
[Obsolete("Use MediatR")]
public static IHost CreateHost(Action<HostApplicationBuilder>? builderOptions = null, string configPath = "appsettings.json", bool useRealDb = false, params string[] args)
{
var builder = Host.CreateApplicationBuilder(args.Any() ? args : null);
var config = builder.Configuration;
builder.Configuration.AddJsonFile(configPath, optional: true, reloadOnChange: true);
builder.Services
.AddEnvelopeGeneratorInfrastructureServices(opt =>
{
if (useRealDb)
{
var connStr = config.GetConnectionString("Default")
?? throw new InvalidOperationException("There is no default connection string in appsettings.json.");
opt.UseSqlServer(connStr);
}
else
opt.UseInMemoryDatabase("MockDB");
})
.AddEnvelopeGeneratorServices(builder.Configuration)
.AddScoped<DocumentStatusService>();
builderOptions?.Invoke(builder);
var host = builder.Build();
return host;
}
}