xonery
xonery
CC#
Created by xonery on 2/14/2023 in #help
❔ Generics
Thanks for taking the time to read my post
// So far, I cannot use TEvent for the cast as
IDomainEventHandler<TAggregateRoot, TAggregateIdentifier, TEvent>
// Is resolved as
IDomainEventHandler<MyAggregateRoot, MyAggregateIdentifier, IEvent<MyAggregateIdentifier>>
// And not
IDomainEventHandler<MyAggregateRoot, MyAggregateIdentifier, MyEvent>
// As I expected it to be, so the cast fails
// So far, I cannot use TEvent for the cast as
IDomainEventHandler<TAggregateRoot, TAggregateIdentifier, TEvent>
// Is resolved as
IDomainEventHandler<MyAggregateRoot, MyAggregateIdentifier, IEvent<MyAggregateIdentifier>>
// And not
IDomainEventHandler<MyAggregateRoot, MyAggregateIdentifier, MyEvent>
// As I expected it to be, so the cast fails
The pattern you showed works as expected but yea looks kinda ugly as i will need a Base class to wrap the casting... I would LOVE TEvent to be Resolved as MyEvent and not IEvent<MyAggregateIdentity>
if(service is IEventHandler handler)
await handler.HandleAsync(@event);
if(service is IEventHandler handler)
await handler.HandleAsync(@event);
6 replies