-
-
Notifications
You must be signed in to change notification settings - Fork 94
Closed
Description
I have the following subscription and an event handler into which I need to inject a command service that works with a specific shard of KurrentDB
var subscriptionId = $"Ledger.StarterDailyAccountOpener.AccountCluster.{location.ClusterIndex}";
builder.Services
.AddKeyedSingleton(subscriptionId, (serviceProvider, _) => serviceProvider.GetRequiredKeyedService<EventStoreClient>(shardKey))
.AddSubscription<StreamSubscription, StreamSubscriptionOptions>(subscriptionId, subscription => subscription
.Configure(options =>
{
options.StreamName = new StreamName("$et-V1.AccountCreated");
options.ResolveLinkTos = true;
options.ThrowOnError = true;
})
.AddEventHandlerWithRetries(serviceProvider => ActivatorUtilities.CreateInstance<StarterDailyAccountOpener>(
serviceProvider,
serviceProvider.GetRequiredKeyedService<ICommandService<DailyAccountState>>(shardKey)), _defaultResiliencePolicy));When starting the host, I get an exception that the StarterDailyAccountOpener handler is not registered with the subscriptionId key. The problem is in the AddCompositionEventHandler method, specifically here
eventuous/src/Core/src/Eventuous.Subscriptions/Registrations/SubscriptionBuilder.cs
Line 79 in 2e7b011
| Services.TryAddKeyedSingleton(SubscriptionId, getInnerHandler); |
In the container, not an instance of the handler is registered, but a function to obtain the handler. It should be
Services.TryAddKeyedSingleton(SubscriptionId, (serviceProvider, _) => getInnerHandler(serviceProvider))Copilot
Metadata
Metadata
Assignees
Labels
No labels