Add MediatR support and CreateOutResCommand handler
Integrated MediatR for command handling by modifying the CreateOutResCommand class to implement the IRequest interface. Added a static EmptyJson property for default JSON serialization and updated Header and Body properties to use it. Introduced CreateOutResCommandHandler to handle command creation using IRepository asynchronously.
This commit is contained in:
parent
41d00036e4
commit
3301b35067
@ -1,8 +1,10 @@
|
|||||||
using System.Text.Json;
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using MediatR;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace ReC.Application.OutResults.Commands;
|
namespace ReC.Application.OutResults.Commands;
|
||||||
|
|
||||||
public class CreateOutResCommand
|
public class CreateOutResCommand : IRequest
|
||||||
{
|
{
|
||||||
public static readonly string EmptyJson = JsonSerializer.Serialize(new object(), options: new()
|
public static readonly string EmptyJson = JsonSerializer.Serialize(new object(), options: new()
|
||||||
{
|
{
|
||||||
@ -16,4 +18,12 @@ public class CreateOutResCommand
|
|||||||
public string Body { get; set; } = EmptyJson;
|
public string Body { get; set; } = EmptyJson;
|
||||||
|
|
||||||
public string? AddedWho { get; set; }
|
public string? AddedWho { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateOutResCommandHandler(IRepository<CreateOutResCommand> repo) : IRequestHandler<CreateOutResCommand>
|
||||||
|
{
|
||||||
|
public Task Handle(CreateOutResCommand request, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
return repo.CreateAsync(request, cancel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user