This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using TestMediator.Interfaces; | |
namespace TestMediator.Command | |
{ | |
public class CadastrarEnderecoCommand : ICommand<string> | |
{ | |
public int Id { get; private set; } | |
public string Logradouro { get; private set; } | |
public string Endereco { get; private set; } | |
public int Numero { get; private set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading; | |
using System.Threading.Tasks; | |
using TestMediator.Interfaces; | |
namespace TestMediator.Mediator | |
{ | |
public class Mediator : IMediator | |
{ | |
private readonly MediatR.IMediator _mediator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading; | |
using System.Threading.Tasks; | |
namespace TestMediator.Interfaces | |
{ | |
public interface IMediator | |
{ | |
Task PublishEvent(object notification, CancellationToken cancellationToken = default); | |
Task PublishEvent<TNotification>(TNotification notification, CancellationToken cancellationToken = default) where TNotification : IEvent; | |
Task<TResponse> SendCommand<TResponse>(ICommand<TResponse> request, CancellationToken cancellationToken = default); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MediatR; | |
namespace TestMediator.Interfaces | |
{ | |
public interface IEventHandle<in TNotification> : INotificationHandler<TNotification> | |
where TNotification : IEvent | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MediatR; | |
namespace TestMediator.Interfaces | |
{ | |
public interface IEvent : INotification | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MediatR; | |
namespace TestMediator.Interfaces | |
{ | |
public interface ICommandHandle<in TRequest, TResponse> : IRequestHandler<TRequest, TResponse> | |
where TRequest : ICommand<TResponse> | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MediatR; | |
namespace TestMediator.Interfaces | |
{ | |
public interface ICommand<out T> : IRequest<T> | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MediatR; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Extensions.Logging; | |
using System.Threading.Tasks; | |
using TestMediator.Notification; | |
namespace TestMediator.Controllers | |
{ | |
[Route("api/[controller]")] | |
[ApiController] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MediatR; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using TestMediator.Notification; | |
namespace TestMediator.NotificationHandle | |
{ | |
public class ProdutoHandle : INotificationHandler<ProdutoNotification> | |
{ | |
public async Task Handle(ProdutoNotification notification, CancellationToken cancellationToken) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MediatR; | |
namespace TestMediator.Notification | |
{ | |
public class ProdutoNotification : INotification | |
{ | |
public int ID { get; private set; } | |
public string Descricao { get; private set; } | |
public decimal Valor { get; private set; } | |
public int QuantidadeEstoque { get; set; } |