Skip to content

Commit bd91a2f

Browse files
committed
Remove MediatR
1 parent f94b1df commit bd91a2f

22 files changed

+92
-97
lines changed

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/ClassifiedAds.Services.Product.Api.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17-
<PackageReference Include="MediatR" Version="12.4.1" />
1817
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.1" />
1918
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
2019
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Commands/AddAuditLogEntryCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
1+
using ClassifiedAds.Application;
2+
using ClassifiedAds.CrossCuttingConcerns.ExtensionMethods;
23
using ClassifiedAds.Domain.Repositories;
34
using ClassifiedAds.Infrastructure.Identity;
45
using ClassifiedAds.Services.Product.Constants;
56
using ClassifiedAds.Services.Product.Entities;
6-
using MediatR;
77
using System;
88
using System.Diagnostics;
99
using System.Threading;
1010
using System.Threading.Tasks;
1111
namespace ClassifiedAds.Services.Product.Commands;
1212

13-
public class AddAuditLogEntryCommand : IRequest
13+
public class AddAuditLogEntryCommand : ICommand
1414
{
1515
public AuditLogEntry AuditLogEntry { get; set; }
1616
}
1717

18-
public class AddAuditLogEntryCommandHandler : IRequestHandler<AddAuditLogEntryCommand>
18+
public class AddAuditLogEntryCommandHandler : ICommandHandler<AddAuditLogEntryCommand>
1919
{
2020
private readonly ICurrentUser _currentUser;
2121
private readonly IRepository<AuditLogEntry, Guid> _auditLogRepository;
@@ -31,7 +31,7 @@ public AddAuditLogEntryCommandHandler(
3131
_outboxEventRepository = outboxEventRepository;
3232
}
3333

34-
public async Task Handle(AddAuditLogEntryCommand command, CancellationToken cancellationToken)
34+
public async Task HandleAsync(AddAuditLogEntryCommand command, CancellationToken cancellationToken)
3535
{
3636
var auditLog = new AuditLogEntry
3737
{

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Commands/AddUpdateProductCommand.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using ClassifiedAds.Application;
2-
using MediatR;
32
using System.Threading;
43
using System.Threading.Tasks;
54

65
namespace ClassifiedAds.Services.Product.Commands;
76

8-
public class AddUpdateProductCommand : IRequest
7+
public class AddUpdateProductCommand : ICommand
98
{
109
public Entities.Product Product { get; set; }
1110
}
1211

13-
public class AddUpdateProductCommandHandler : IRequestHandler<AddUpdateProductCommand>
12+
public class AddUpdateProductCommandHandler : ICommandHandler<AddUpdateProductCommand>
1413
{
1514
private readonly ICrudService<Entities.Product> _productService;
1615

@@ -19,7 +18,7 @@ public AddUpdateProductCommandHandler(ICrudService<Entities.Product> productServ
1918
_productService = productService;
2019
}
2120

22-
public async Task Handle(AddUpdateProductCommand command, CancellationToken cancellationToken = default)
21+
public async Task HandleAsync(AddUpdateProductCommand command, CancellationToken cancellationToken = default)
2322
{
2423
await _productService.AddOrUpdateAsync(command.Product);
2524
}

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Commands/DeleteProductCommand.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using ClassifiedAds.Application;
2-
using MediatR;
32
using System.Threading;
43
using System.Threading.Tasks;
54

65
namespace ClassifiedAds.Services.Product.Commands;
76

8-
public class DeleteProductCommand : IRequest
7+
public class DeleteProductCommand : ICommand
98
{
109
public Entities.Product Product { get; set; }
1110
}
1211

13-
public class DeleteProductCommandHandler : IRequestHandler<DeleteProductCommand>
12+
public class DeleteProductCommandHandler : ICommandHandler<DeleteProductCommand>
1413
{
1514
private readonly ICrudService<Entities.Product> _productService;
1615

@@ -19,7 +18,7 @@ public DeleteProductCommandHandler(ICrudService<Entities.Product> productService
1918
_productService = productService;
2019
}
2120

22-
public async Task Handle(DeleteProductCommand command, CancellationToken cancellationToken = default)
21+
public async Task HandleAsync(DeleteProductCommand command, CancellationToken cancellationToken = default)
2322
{
2423
await _productService.DeleteAsync(command.Product);
2524
}

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Commands/PublishEventsCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using ClassifiedAds.CrossCuttingConcerns.DateTimes;
1+
using ClassifiedAds.Application;
2+
using ClassifiedAds.CrossCuttingConcerns.DateTimes;
23
using ClassifiedAds.Domain.Infrastructure.MessageBrokers;
34
using ClassifiedAds.Domain.Repositories;
45
using ClassifiedAds.Services.Product.Entities;
5-
using MediatR;
66
using Microsoft.Extensions.Logging;
77
using System;
88
using System.Linq;
@@ -11,12 +11,12 @@
1111

1212
namespace ClassifiedAds.Services.Product.Commands;
1313

14-
public class PublishEventsCommand : IRequest
14+
public class PublishEventsCommand : ICommand
1515
{
1616
public int SentEventsCount { get; set; }
1717
}
1818

19-
public class PublishEventsCommandHandler : IRequestHandler<PublishEventsCommand>
19+
public class PublishEventsCommandHandler : ICommandHandler<PublishEventsCommand>
2020
{
2121
private readonly ILogger<PublishEventsCommandHandler> _logger;
2222
private readonly IDateTimeProvider _dateTimeProvider;
@@ -34,7 +34,7 @@ public PublishEventsCommandHandler(ILogger<PublishEventsCommandHandler> logger,
3434
_messageBus = messageBus;
3535
}
3636

37-
public async Task Handle(PublishEventsCommand command, CancellationToken cancellationToken = default)
37+
public async Task HandleAsync(PublishEventsCommand command, CancellationToken cancellationToken = default)
3838
{
3939
var events = _outboxEventRepository.GetQueryableSet()
4040
.Where(x => !x.Published)

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Endpoints/CreateProductRequest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using ClassifiedAds.Infrastructure.Web.MinimalApis;
1+
using ClassifiedAds.Application;
2+
using ClassifiedAds.Infrastructure.Web.MinimalApis;
23
using ClassifiedAds.Services.Product.Authorization;
34
using ClassifiedAds.Services.Product.Commands;
45
using ClassifiedAds.Services.Product.RateLimiterPolicies;
56
using FluentValidation;
6-
using MediatR;
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.AspNetCore.Mvc;
@@ -60,7 +60,7 @@ public static void MapEndpoint(IEndpointRouteBuilder builder)
6060
});
6161
}
6262

63-
private static async Task<IResult> HandleAsync(IMediator dispatcher, [FromBody] CreateProductRequest request, IValidator<CreateProductRequest> validator)
63+
private static async Task<IResult> HandleAsync(Dispatcher dispatcher, [FromBody] CreateProductRequest request, IValidator<CreateProductRequest> validator)
6464
{
6565
var validationResult = await validator.ValidateAsync(request);
6666
if (!validationResult.IsValid)
@@ -76,7 +76,7 @@ private static async Task<IResult> HandleAsync(IMediator dispatcher, [FromBody]
7676
Description = request.Description,
7777
};
7878

79-
await dispatcher.Send(new AddUpdateProductCommand { Product = product });
79+
await dispatcher.DispatchAsync(new AddUpdateProductCommand { Product = product });
8080

8181
var response = new CreateProductResponse
8282
{

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Endpoints/DeleteProductRequest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using ClassifiedAds.Infrastructure.Web.MinimalApis;
1+
using ClassifiedAds.Application;
2+
using ClassifiedAds.Infrastructure.Web.MinimalApis;
23
using ClassifiedAds.Services.Product.Authorization;
34
using ClassifiedAds.Services.Product.Commands;
45
using ClassifiedAds.Services.Product.Queries;
56
using ClassifiedAds.Services.Product.RateLimiterPolicies;
6-
using MediatR;
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.AspNetCore.Routing;
@@ -31,11 +31,11 @@ public static void MapEndpoint(IEndpointRouteBuilder builder)
3131
});
3232
}
3333

34-
private static async Task<IResult> HandleAsync(IMediator dispatcher, Guid id)
34+
private static async Task<IResult> HandleAsync(Dispatcher dispatcher, Guid id)
3535
{
36-
var product = await dispatcher.Send(new GetProductQuery { Id = id, ThrowNotFoundIfNull = true });
36+
var product = await dispatcher.DispatchAsync(new GetProductQuery { Id = id, ThrowNotFoundIfNull = true });
3737

38-
await dispatcher.Send(new DeleteProductCommand { Product = product });
38+
await dispatcher.DispatchAsync(new DeleteProductCommand { Product = product });
3939

4040
return Results.Ok();
4141
}

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Endpoints/ExportProductsAsCsvRequest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using ClassifiedAds.CrossCuttingConcerns.Csv;
1+
using ClassifiedAds.Application;
2+
using ClassifiedAds.CrossCuttingConcerns.Csv;
23
using ClassifiedAds.Infrastructure.Web.MinimalApis;
34
using ClassifiedAds.Services.Product.Csv;
45
using ClassifiedAds.Services.Product.Queries;
56
using ClassifiedAds.Services.Product.RateLimiterPolicies;
6-
using MediatR;
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.AspNetCore.Routing;
@@ -30,10 +30,10 @@ public static void MapEndpoint(IEndpointRouteBuilder builder)
3030
});
3131
}
3232

33-
private static async Task<IResult> HandleAsync(IMediator dispatcher,
33+
private static async Task<IResult> HandleAsync(Dispatcher dispatcher,
3434
ICsvWriter<ExportProductsToCsv> productCsvWriter)
3535
{
36-
var products = await dispatcher.Send(new GetProductsQuery());
36+
var products = await dispatcher.DispatchAsync(new GetProductsQuery());
3737
using var stream = new MemoryStream();
3838
await productCsvWriter.WriteAsync(new ExportProductsToCsv { Products = products }, stream);
3939
return Results.File(stream.ToArray(), MediaTypeNames.Application.Octet, "Products.csv");

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Endpoints/ExportProductsAsPdfRequest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using ClassifiedAds.CrossCuttingConcerns.Pdf;
1+
using ClassifiedAds.Application;
2+
using ClassifiedAds.CrossCuttingConcerns.Pdf;
23
using ClassifiedAds.Infrastructure.Web.MinimalApis;
34
using ClassifiedAds.Services.Product.Pdf;
45
using ClassifiedAds.Services.Product.Queries;
56
using ClassifiedAds.Services.Product.RateLimiterPolicies;
6-
using MediatR;
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.AspNetCore.Routing;
@@ -29,9 +29,9 @@ public static void MapEndpoint(IEndpointRouteBuilder builder)
2929
});
3030
}
3131

32-
private static async Task<IResult> HandleAsync(IMediator dispatcher, IPdfWriter<ExportProductsToPdf> pdfWriter)
32+
private static async Task<IResult> HandleAsync(Dispatcher dispatcher, IPdfWriter<ExportProductsToPdf> pdfWriter)
3333
{
34-
var products = await dispatcher.Send(new GetProductsQuery());
34+
var products = await dispatcher.DispatchAsync(new GetProductsQuery());
3535
var bytes = await pdfWriter.GetBytesAsync(new ExportProductsToPdf { Products = products });
3636

3737
return Results.File(bytes, MediaTypeNames.Application.Octet, "Products.pdf");

src/Microservices/Services.Product/ClassifiedAds.Services.Product.Api/Endpoints/GetProductAuditLogsRequest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using ClassifiedAds.Infrastructure.Web.MinimalApis;
1+
using ClassifiedAds.Application;
2+
using ClassifiedAds.Infrastructure.Web.MinimalApis;
23
using ClassifiedAds.Services.Product.Authorization;
34
using ClassifiedAds.Services.Product.DTOs;
45
using ClassifiedAds.Services.Product.Models;
56
using ClassifiedAds.Services.Product.Queries;
67
using ClassifiedAds.Services.Product.RateLimiterPolicies;
7-
using MediatR;
88
using Microsoft.AspNetCore.Builder;
99
using Microsoft.AspNetCore.Http;
1010
using Microsoft.AspNetCore.Routing;
@@ -33,9 +33,9 @@ public static void MapEndpoint(IEndpointRouteBuilder builder)
3333
});
3434
}
3535

36-
private static async Task<IResult> HandleAsync(IMediator dispatcher, Guid id)
36+
private static async Task<IResult> HandleAsync(Dispatcher dispatcher, Guid id)
3737
{
38-
var logs = await dispatcher.Send(new GetAuditEntriesQuery { ObjectId = id.ToString() });
38+
var logs = await dispatcher.DispatchAsync(new GetAuditEntriesQuery { ObjectId = id.ToString() });
3939

4040
List<dynamic> entries = new List<dynamic>();
4141
ProductModel previous = null;

0 commit comments

Comments
 (0)