Skip to content

Commit 6b91434

Browse files
agehrkeAndreas Gehrke
and
Andreas Gehrke
authored
Allow CommandHandlers to have scoped dependencies (#64)
* Register ICommandProcessorFactory, ICommandHandlerFactory and CommandProcessor as transient to allow to CommandHandler to use scoped dependencies. * Update changelog --------- Co-authored-by: Andreas Gehrke <[email protected]>
1 parent 3985b36 commit 6b91434

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Changed
11+
12+
- Changed `ICommandProcessorFactory`, `ICommandHandlerFactory` and `CommandProcessor<>` to be
13+
registered as transient rather than singleton. This allows `CommandHandler` implementations to use
14+
dependencies registered as scoped.
15+
816
## [1.17.0] - 2025-03-21
917

1018
### Fixed

src/Atc.Cosmos.EventStore.Cqrs/DependencyInjection/EventStoreOptionsBuilderExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public static EventStoreOptionsBuilder UseCQRS(
2020

2121
builder.Services.AddSingleton(typeof(IStateProjector<>), typeof(StateProjector<>));
2222
builder.Services.AddSingleton(typeof(IStateWriter<>), typeof(StateWriter<>));
23-
builder.Services.AddSingleton(typeof(ICommandProcessor<>), typeof(CommandProcessor<>));
24-
builder.Services.AddSingleton<ICommandProcessorFactory, CommandProcessorFactory>();
25-
builder.Services.AddSingleton<ICommandHandlerFactory, CommandHandlerFactory>();
23+
builder.Services.AddTransient(typeof(ICommandProcessor<>), typeof(CommandProcessor<>));
24+
builder.Services.AddTransient<ICommandProcessorFactory, CommandProcessorFactory>();
25+
builder.Services.AddTransient<ICommandHandlerFactory, CommandHandlerFactory>();
2626
builder.Services.AddSingleton<ICommandTelemetry, CommandTelemetry>();
2727

2828
builder.Services.AddSingleton<IProjectionOptionsFactory, ProjectionOptionsFactory>();

0 commit comments

Comments
 (0)