cqrs.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using FluentValidation;
|
||||
using PoweredSoft.CQRS.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Commands
|
||||
{
|
||||
public class CreatePersonCommand
|
||||
{
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
}
|
||||
|
||||
public class CreatePersonCommandValidator : AbstractValidator<CreatePersonCommand>
|
||||
{
|
||||
public CreatePersonCommandValidator()
|
||||
{
|
||||
RuleFor(t => t.FirstName).NotEmpty();
|
||||
RuleFor(t => t.LastName).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreatePersonCommandHandler : ICommandHandler<CreatePersonCommand>
|
||||
{
|
||||
public Task HandleAsync(CreatePersonCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using FluentValidation;
|
||||
using PoweredSoft.CQRS.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Demo.Commands
|
||||
{
|
||||
public class EchoCommand
|
||||
{
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
public class EchoCommandValidator : AbstractValidator<EchoCommand>
|
||||
{
|
||||
public EchoCommandValidator()
|
||||
{
|
||||
RuleFor(t => t.Message).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class EchoCommandHandler : ICommandHandler<EchoCommand, string>
|
||||
{
|
||||
public Task<string> HandleAsync(EchoCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.FromResult(command.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user