[ad058b3] | 1 | using FinkiChattery.Common.Mediator.Contracs;
|
---|
[e6a6d9a] | 2 | using FinkiChattery.Common.Mediator.Interfaces;
|
---|
[ad058b3] | 3 | using MediatR;
|
---|
| 4 | using System.ComponentModel;
|
---|
[e6a6d9a] | 5 | using System.Threading;
|
---|
| 6 | using System.Threading.Tasks;
|
---|
| 7 |
|
---|
| 8 | namespace FinkiChattery.Common.Mediator
|
---|
| 9 | {
|
---|
| 10 | public class MediatorService : IMediatorService
|
---|
| 11 | {
|
---|
| 12 | private readonly IMediator mediator;
|
---|
| 13 |
|
---|
| 14 | public MediatorService(IMediator mediator)
|
---|
| 15 | {
|
---|
| 16 | this.mediator = mediator;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public async Task<TResponse> SendAsync<TResponse>(ICommand<TResponse> request, CancellationToken cancellationToken)
|
---|
| 20 | {
|
---|
| 21 | return await mediator.Send(request, cancellationToken);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public async Task<TResponse> SendAsync<TResponse>(ICommand<TResponse> request)
|
---|
| 25 | {
|
---|
| 26 | return await mediator.Send(request);
|
---|
| 27 | }
|
---|
[ad058b3] | 28 |
|
---|
| 29 | public async Task PublishAsync<TNotification>(TNotification notification) where TNotification : IEvent
|
---|
| 30 | {
|
---|
| 31 | await mediator.Publish(notification, default);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | [DisplayName("{0}")]
|
---|
| 35 | public async Task PublishAsync<TNotification>(string jobName, TNotification notification) where TNotification : IEvent
|
---|
| 36 | {
|
---|
| 37 | await mediator.Publish(notification, default);
|
---|
| 38 | }
|
---|
[b25b9ea] | 39 |
|
---|
| 40 | public async Task<TResponse> SendQueryAsync<TResponse>(IQuery<TResponse> request, CancellationToken cancellationToken)
|
---|
| 41 | {
|
---|
| 42 | return await mediator.Send(request, cancellationToken);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public async Task<TResponse> SendQueryAsync<TResponse>(IQuery<TResponse> request)
|
---|
| 46 | {
|
---|
| 47 | return await mediator.Send(request);
|
---|
| 48 | }
|
---|
[e6a6d9a] | 49 | }
|
---|
| 50 | }
|
---|