RedBus
RedBus copied to clipboard
No messages received with wrapped method
Hi, I found an issue that if you have for example this wrapper:
private static readonly IEventBus EventBus;
public static void Publish(EventBase message)
{
EventBus.Publish(message);
}
// in another class
EventBusWrapper.Publish(new Payload(payload))
EventBus cannot find any event except EventBase.
But if you declare the method as below, everything works as should:
public static void Publish<T>(T message) where T : EventBase
{
EventBus.Publish(message);
}
I spent a few hours to find a root cause. Maybe it saves time for others.
Got the same problem! Thanks
As RedBus determines the type of the event at compile-time, the event must be casted to the desired type at compile-time which might not be possible in any project (it might fit for your project, but for mine it does not work without refactoring the whole project 😄)
I proposed a PR which determines the type of the event at runtime.