eventuous: Using MapDiscoveredCommands with multiple aggregates results in error 'No handler found for command Object '
Describe the bug
In a ASP NET Web Application, app.MapDiscoveredCommands() is not working as expected. All correctly registered commands are found but all are failing on execution with error
{
"type": "CommandHandlerNotFound`1",
"title": "No handler found for command Object",
"status": 500,
"detail": "Eventuous.Exceptions+CommandHandlerNotFound`1[System.Object]: No handler found for command Object"
}
To Reproduce
See attached solution TestEventuous.zip with the following structure:
The solution contains Api, Application and Domain projects with commands for Car (StartEngine) and Train (OpenDoors) and the corresponding CommandServices.
[AggregateCommands<Car>]
public static class CarCommands
{
[HttpCommand(Route = "car/start-engine")]
public sealed record StartEngine
{
public required string CarId { get; init; }
}
}
[AggregateCommands<Train>]
public static class TrainCommands
{
[HttpCommand(Route = "train/open-doors")]
public sealed record OpenDoors
{
public required string TrainId { get; init; }
}
}
public sealed class CarService : CommandService<Car, CarState, CarId>
{
public CarService(IAggregateStore? store, AggregateFactoryRegistry? factoryRegistry = null, StreamNameMap? streamNameMap = null, TypeMapper? typeMap = null)
: base(store, factoryRegistry, streamNameMap, typeMap)
{
On<CarCommands.StartEngine>()
.GetId(_ => new CarId(Guid.NewGuid().ToString()))
.Act((car, _) => car.StartEngine());
}
}
public sealed class TrainService : CommandService<Train, TrainState, TrainId>
{
public TrainService(IAggregateStore? store, AggregateFactoryRegistry? factoryRegistry = null, StreamNameMap? streamNameMap = null, TypeMapper? typeMap = null)
: base(store, factoryRegistry, streamNameMap, typeMap)
{
On<TrainCommands.OpenDoors>()
.GetId(_ => new TrainId(Guid.NewGuid().ToString()))
.Act((Train, _) => Train.OpenDoors());
}
}
Running the application displays swagger with two endpoint car/start-engine and train/open-doors. Executing those endpoints yields the error described.
When changing
app.MapDiscoveredCommands(typeof(ApplicationModule).Assembly);
to
app.MapDiscoveredCommands<Car>(typeof(ApplicationModule).Assembly);
then car command is working as expected (but not train, but that is wanted, as described in the docs)
Expected behavior All discovered commands should reach their corresponding handler.
Screenshots
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 16 (16 by maintainers)
Commits related to this issue
- Fixed bug in CommandService Regarding #264 When a command handler is not registered, the exception message contains now the correct type. — committed to iappwebdev/eventuous_tests by iappwebdev 9 months ago
- Fixed bug in CommandService (#274) Regarding #264 When a command handler is not registered, the exception message contains now the correct type. — committed to Eventuous/eventuous by iappwebdev 9 months ago
- Tests required for #264 — committed to iappwebdev/eventuous_tests by iappwebdev 9 months ago
I am closing it as the tests you added are passing. Feel free to reopen it, or open a new one if something is still not working.
0.15.0-beta.4.19 is on MyGet
Your test passes now, should we consider the issue resolved?