-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f77baa
commit 109d7ed
Showing
10 changed files
with
108 additions
and
48 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Source/ImoutoRebirth.Common/ImoutoRebirth.Common.Cqrs/Behaviors/EventProcessingBehavior.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using ImoutoRebirth.Common.Cqrs.Events; | ||
using ImoutoRebirth.Common.Domain; | ||
using MediatR; | ||
|
||
namespace ImoutoRebirth.Common.Cqrs.Behaviors; | ||
|
||
internal class EventProcessingBehavior<TRequest, TResponse> | ||
: IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : notnull | ||
{ | ||
private readonly IEventPublisher _eventPublisher; | ||
private readonly IEventStorage _eventStorage; | ||
|
||
public EventProcessingBehavior(IEventStorage eventStorage, IEventPublisher eventPublisher) | ||
{ | ||
_eventPublisher = eventPublisher; | ||
_eventStorage = eventStorage; | ||
} | ||
|
||
public async Task<TResponse> Handle( | ||
TRequest request, | ||
RequestHandlerDelegate<TResponse> next, | ||
CancellationToken ct) | ||
{ | ||
var mark = Guid.NewGuid(); | ||
_eventStorage.Mark(mark); | ||
|
||
var response = await next(); | ||
|
||
var events = _eventStorage.GetAll(mark); | ||
await InvokeEventsAsync(events, ct); | ||
|
||
return response; | ||
} | ||
|
||
private async Task InvokeEventsAsync(IReadOnlyCollection<IDomainEvent> events, CancellationToken ct) | ||
{ | ||
foreach (var domainEvent in events) | ||
{ | ||
await _eventPublisher.Publish(domainEvent, ct); | ||
} | ||
} | ||
} |
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
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
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
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
26 changes: 13 additions & 13 deletions
26
...usSlice/NotesUpdatedDomainEventHandler.cs → .../Commands/RequestMetadataUpdateCommand.cs
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
22 changes: 22 additions & 0 deletions
22
...eido/ImoutoRebirth.Meido.Application/ParsingStatusSlice/PostsUpdatedDomainEventHandler.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using ImoutoRebirth.Common.Cqrs.Events; | ||
using ImoutoRebirth.Meido.Application.ParsingStatusSlice.Commands; | ||
using ImoutoRebirth.Meido.Domain.SourceActualizingStateAggregate; | ||
using MediatR; | ||
|
||
namespace ImoutoRebirth.Meido.Application.ParsingStatusSlice; | ||
|
||
internal class PostsUpdatedDomainEventHandler : DomainEventNotificationHandler<PostsUpdatedDomainEvent> | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public PostsUpdatedDomainEventHandler(IMediator mediator) => _mediator = mediator; | ||
|
||
protected override async Task Handle(PostsUpdatedDomainEvent domainEvent, CancellationToken ct) | ||
{ | ||
var (sourceActualizingState, postsIdsWithUpdatedNotes) = domainEvent; | ||
|
||
await _mediator.Send( | ||
new RequestMetadataUpdateCommand(postsIdsWithUpdatedNotes, sourceActualizingState.Source), | ||
ct); | ||
} | ||
} |
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
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
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