diff --git a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommand.cs b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommand.cs index fd557599..599a84c8 100644 --- a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommand.cs +++ b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommand.cs @@ -36,7 +36,10 @@ public record CreateEnvelopeCommand : IRequest public int UserId { get; set; } /// - /// if true, use ; otherwise, use + /// Determines which component is used for envelope processing. + /// When true, processing is delegated to ; + /// when false, is used instead. + /// Note: should only be used in testing scenarios. /// [JsonIgnore] [NotMapped] diff --git a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs index e7a39711..1fde1bf2 100644 --- a/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs +++ b/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommandHandler.cs @@ -2,6 +2,9 @@ using EnvelopeGenerator.Application.Interfaces.SQLExecutor; using EnvelopeGenerator.Application.Dto; using MediatR; +using Microsoft.Extensions.DependencyInjection; +using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.Application.Envelopes.Commands; @@ -10,18 +13,22 @@ namespace EnvelopeGenerator.Application.Envelopes.Commands; /// public class CreateEnvelopeCommandHandler : IRequestHandler { - private readonly IEnvelopeExecutor _envelopeExecutor; + private readonly IServiceProvider _provider; + + private IEnvelopeExecutor Executor => _provider.GetRequiredService(); + + private IRepository Repository => _provider.GetRequiredService>(); private readonly IMapper _mapper; /// /// /// - /// + /// /// - public CreateEnvelopeCommandHandler(IEnvelopeExecutor envelopeExecutor, IMapper mapper) + public CreateEnvelopeCommandHandler(IServiceProvider provider, IMapper mapper) { - _envelopeExecutor = envelopeExecutor; + _provider = provider; _mapper = mapper; } @@ -29,12 +36,14 @@ public class CreateEnvelopeCommandHandler : IRequestHandler /// - /// + /// /// - public async Task Handle(CreateEnvelopeCommand request, CancellationToken cancellationToken) + public async Task Handle(CreateEnvelopeCommand request, CancellationToken cancel) { - var envelope = await _envelopeExecutor.CreateEnvelopeAsync(request.UserId, request.Title, request.Message, request.TFAEnabled, cancellationToken); + var envelope = request.UseSQLExecutor + ? await Executor.CreateEnvelopeAsync(request.UserId, request.Title, request.Message, request.TFAEnabled, cancel) + : await Repository.CreateAsync(request, cancel); return _mapper.Map(envelope); } -} +} \ No newline at end of file