Skip to content

Commit

Permalink
Replaced IPublisher by ISender in command handlers. (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 authored Mar 28, 2024
1 parent e13cc93 commit 6504ca7
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace Faktur.Application.Articles.Commands;
internal class CreateArticleCommandHandler : IRequestHandler<CreateArticleCommand, Article>
{
private readonly IArticleQuerier _articleQuerier;
private readonly IPublisher _publisher;
private readonly ISender _sender;

public CreateArticleCommandHandler(IArticleQuerier articleQuerier, IPublisher publisher)
public CreateArticleCommandHandler(IArticleQuerier articleQuerier, ISender sender)
{
_articleQuerier = articleQuerier;
_publisher = publisher;
_sender = sender;
}

public async Task<Article> Handle(CreateArticleCommand command, CancellationToken cancellationToken)
Expand All @@ -32,7 +32,7 @@ public async Task<Article> Handle(CreateArticleCommand command, CancellationToke

article.Update(command.ActorId);

await _publisher.Publish(new SaveArticleCommand(article), cancellationToken);
await _sender.Send(new SaveArticleCommand(article), cancellationToken);

return await _articleQuerier.ReadAsync(article, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ internal class ReplaceArticleCommandHandler : IRequestHandler<ReplaceArticleComm
{
private readonly IArticleQuerier _articleQuerier;
private readonly IArticleRepository _articleRepository;
private readonly IPublisher _publisher;
private readonly ISender _sender;

public ReplaceArticleCommandHandler(IArticleQuerier articleQuerier, IArticleRepository articleRepository, IPublisher publisher)
public ReplaceArticleCommandHandler(IArticleQuerier articleQuerier, IArticleRepository articleRepository, ISender sender)
{
_articleQuerier = articleQuerier;
_articleRepository = articleRepository;
_publisher = publisher;
_sender = sender;
}

public async Task<Article?> Handle(ReplaceArticleCommand command, CancellationToken cancellationToken)
Expand Down Expand Up @@ -54,7 +54,7 @@ public ReplaceArticleCommandHandler(IArticleQuerier articleQuerier, IArticleRepo

article.Update(command.ActorId);

await _publisher.Publish(new SaveArticleCommand(article), cancellationToken);
await _sender.Send(new SaveArticleCommand(article), cancellationToken);

return await _articleQuerier.ReadAsync(article, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace Faktur.Application.Articles.Commands;

internal record SaveArticleCommand(ArticleAggregate Article) : INotification;
internal record SaveArticleCommand(ArticleAggregate Article) : IRequest;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Faktur.Application.Articles.Commands;

internal class SaveArticleCommandHandler : INotificationHandler<SaveArticleCommand>
internal class SaveArticleCommandHandler : IRequestHandler<SaveArticleCommand>
{
private readonly IArticleRepository _articleRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ internal class UpdateArticleCommandHandler : IRequestHandler<UpdateArticleComman
{
private readonly IArticleQuerier _articleQuerier;
private readonly IArticleRepository _articleRepository;
private readonly IPublisher _publisher;
private readonly ISender _sender;

public UpdateArticleCommandHandler(IArticleQuerier articleQuerier, IArticleRepository articleRepository, IPublisher publisher)
public UpdateArticleCommandHandler(IArticleQuerier articleQuerier, IArticleRepository articleRepository, ISender sender)
{
_articleQuerier = articleQuerier;
_articleRepository = articleRepository;
_publisher = publisher;
_sender = sender;
}

public async Task<Article?> Handle(UpdateArticleCommand command, CancellationToken cancellationToken)
Expand Down Expand Up @@ -46,7 +46,7 @@ public UpdateArticleCommandHandler(IArticleQuerier articleQuerier, IArticleRepos

article.Update(command.ActorId);

await _publisher.Publish(new SaveArticleCommand(article), cancellationToken);
await _sender.Send(new SaveArticleCommand(article), cancellationToken);

return await _articleQuerier.ReadAsync(article, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ internal class CreateOrReplaceProductCommandHandler : IRequestHandler<CreateOrRe
private readonly IArticleRepository _articleRepository;
private readonly IProductQuerier _productQuerier;
private readonly IProductRepository _productRepository;
private readonly IPublisher _publisher;
private readonly ISender _sender;
private readonly IStoreRepository _storeRepository;

public CreateOrReplaceProductCommandHandler(IArticleRepository articleRepository, IProductQuerier productQuerier,
IProductRepository productRepository, IPublisher publisher, IStoreRepository storeRepository)
IProductRepository productRepository, ISender sender, IStoreRepository storeRepository)
{
_articleRepository = articleRepository;
_productQuerier = productQuerier;
_productRepository = productRepository;
_publisher = publisher;
_sender = sender;
_storeRepository = storeRepository;
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public async Task<CreateOrReplaceProductResult> Handle(CreateOrReplaceProductCom

product.Update(command.ActorId);

await _publisher.Publish(new SaveProductCommand(product), cancellationToken);
await _sender.Send(new SaveProductCommand(product), cancellationToken);

Product result = await _productQuerier.ReadAsync(product, cancellationToken);
return new CreateOrReplaceProductResult(isCreated, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace Faktur.Application.Products.Commands;

internal record SaveProductCommand(ProductAggregate Product) : INotification;
internal record SaveProductCommand(ProductAggregate Product) : IRequest;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Faktur.Application.Products.Commands;

internal class SaveProductCommandHandler : INotificationHandler<SaveProductCommand>
internal class SaveProductCommandHandler : IRequestHandler<SaveProductCommand>
{
private readonly IProductRepository _productRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ internal class UpdateProductCommandHandler : IRequestHandler<UpdateProductComman
{
private readonly IProductQuerier _productQuerier;
private readonly IProductRepository _productRepository;
private readonly IPublisher _publisher;
private readonly ISender _sender;
private readonly IStoreRepository _storeRepository;

public UpdateProductCommandHandler(IProductQuerier productQuerier, IProductRepository productRepository, IPublisher publisher, IStoreRepository storeRepository)
public UpdateProductCommandHandler(IProductQuerier productQuerier, IProductRepository productRepository, ISender sender, IStoreRepository storeRepository)
{
_productQuerier = productQuerier;
_productRepository = productRepository;
_publisher = publisher;
_sender = sender;
_storeRepository = storeRepository;
}

Expand Down Expand Up @@ -79,7 +79,7 @@ public UpdateProductCommandHandler(IProductQuerier productQuerier, IProductRepos

product.Update(command.ActorId);

await _publisher.Publish(new SaveProductCommand(product), cancellationToken);
await _sender.Send(new SaveProductCommand(product), cancellationToken);

return await _productQuerier.ReadAsync(product, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace Faktur.Application.Taxes.Commands;

internal class CreateTaxCommandHandler : IRequestHandler<CreateTaxCommand, Tax>
{
private readonly IPublisher _publisher;
private readonly ISender _sender;
private readonly ITaxQuerier _taxQuerier;

public CreateTaxCommandHandler(IPublisher publisher, ITaxQuerier taxQuerier)
public CreateTaxCommandHandler(ISender sender, ITaxQuerier taxQuerier)
{
_publisher = publisher;
_sender = sender;
_taxQuerier = taxQuerier;
}

Expand All @@ -31,7 +31,7 @@ public async Task<Tax> Handle(CreateTaxCommand command, CancellationToken cancel

tax.Update(command.ActorId);

await _publisher.Publish(new SaveTaxCommand(tax), cancellationToken);
await _sender.Send(new SaveTaxCommand(tax), cancellationToken);

return await _taxQuerier.ReadAsync(tax, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace Faktur.Application.Taxes.Commands;

internal class ReplaceTaxCommandHandler : IRequestHandler<ReplaceTaxCommand, Tax?>
{
private readonly IPublisher _publisher;
private readonly ISender _sender;
private readonly ITaxQuerier _taxQuerier;
private readonly ITaxRepository _taxRepository;

public ReplaceTaxCommandHandler(IPublisher publisher, ITaxQuerier taxQuerier, ITaxRepository taxRepository)
public ReplaceTaxCommandHandler(ISender sender, ITaxQuerier taxQuerier, ITaxRepository taxRepository)
{
_publisher = publisher;
_sender = sender;
_taxQuerier = taxQuerier;
_taxRepository = taxRepository;
}
Expand Down Expand Up @@ -54,7 +54,7 @@ public ReplaceTaxCommandHandler(IPublisher publisher, ITaxQuerier taxQuerier, IT

tax.Update(command.ActorId);

await _publisher.Publish(new SaveTaxCommand(tax), cancellationToken);
await _sender.Send(new SaveTaxCommand(tax), cancellationToken);

return await _taxQuerier.ReadAsync(tax, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace Faktur.Application.Taxes.Commands;

internal record SaveTaxCommand(TaxAggregate Tax) : INotification;
internal record SaveTaxCommand(TaxAggregate Tax) : IRequest;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Faktur.Application.Taxes.Commands;

internal class SaveTaxCommandHandler : INotificationHandler<SaveTaxCommand>
internal class SaveTaxCommandHandler : IRequestHandler<SaveTaxCommand>
{
private readonly ITaxRepository _taxRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace Faktur.Application.Taxes.Commands;

internal class UpdateTaxCommandHandler : IRequestHandler<UpdateTaxCommand, Tax?>
{
private readonly IPublisher _publisher;
private readonly ISender _sender;
private readonly ITaxQuerier _taxQuerier;
private readonly ITaxRepository _taxRepository;

public UpdateTaxCommandHandler(IPublisher publisher, ITaxQuerier taxQuerier, ITaxRepository taxRepository)
public UpdateTaxCommandHandler(ISender sender, ITaxQuerier taxQuerier, ITaxRepository taxRepository)
{
_publisher = publisher;
_sender = sender;
_taxQuerier = taxQuerier;
_taxRepository = taxRepository;
}
Expand Down Expand Up @@ -48,7 +48,7 @@ public UpdateTaxCommandHandler(IPublisher publisher, ITaxQuerier taxQuerier, ITa

tax.Update(command.ActorId);

await _publisher.Publish(new SaveTaxCommand(tax), cancellationToken);
await _sender.Send(new SaveTaxCommand(tax), cancellationToken);

return await _taxQuerier.ReadAsync(tax, cancellationToken);
}
Expand Down

0 comments on commit 6504ca7

Please sign in to comment.