-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use lifetimescope when dispatching multiple commands for municip…
…ality proposal
- Loading branch information
1 parent
f05a88f
commit 965a6e6
Showing
5 changed files
with
128 additions
and
31 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
src/StreetNameRegistry.Api.BackOffice.Handlers.Lambda/ScopedIdempotentCommandHandler.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,31 @@ | ||
namespace StreetNameRegistry.Api.BackOffice.Handlers.Lambda | ||
{ | ||
using Autofac; | ||
using Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency; | ||
|
||
public interface IScopedIdempotentCommandHandler: IIdempotentCommandHandler | ||
{ | ||
} | ||
|
||
public class ScopedIdempotentCommandHandler : IScopedIdempotentCommandHandler | ||
{ | ||
private readonly ILifetimeScope _container; | ||
|
||
public ScopedIdempotentCommandHandler(ILifetimeScope container) | ||
{ | ||
_container = container; | ||
} | ||
|
||
public async Task<long> Dispatch(Guid? commandId, object command, IDictionary<string, object> metadata, CancellationToken cancellationToken) | ||
{ | ||
await using var scope = _container.BeginLifetimeScope(); | ||
|
||
var resolver = scope.Resolve<IIdempotentCommandHandler>(); | ||
return await resolver.Dispatch( | ||
commandId, | ||
command, | ||
metadata, | ||
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
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