I'm having some trouble with my handlers not "catching" my events. My current structure is that I have a wrapper around Rebus in a separate package that wraps around Rebus' methods and expose a factory to use with i.e. Autofac - so far so good.
I then have all my domain events in separate packages and namespaces so they don't know about Rebus and vice versa. he all derive from the type IDistributedEvent
and implements the abstract type DistributedEvent
.
When I publish an event, say MessageSent
, I then in my wrapper make an envelope event BusEvent
where I set the domain event as a Payload
property:
public Task Publish<T>( T payload, TimeSpan expiration ) where T : IDistributedEvent
{
var message = new BusEvent<T> { Payload = payload };
return InternalBus.Publish( message, new Dictionary<string, string> {
{ Headers.TimeToBeReceived, expiration.ToString() },
{ "pd-version", payload.EventVersion.ToString() },
} );
}
The reason for this is to be able to add some metadata over time (But maybe this is the wrong way of doing this).
Anyway, my problem is now that my handlers is no recognised as a handler that can handle the type BusEvent<MessageSent>
, even though I create handlers using the interface IHandleMessages<BusEvent<T>> where T : IDistributedEvent
So the question is: Am I doing it wrong here, or is this simply just a bad way of doing it. Thus, I should just remove the enveloping type and handle the domain event type directly?