RedBus icon indicating copy to clipboard operation
RedBus copied to clipboard

No messages received with wrapped method

Open fryette opened this issue 5 years ago • 2 comments

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.

fryette avatar Aug 24 '19 16:08 fryette

Got the same problem! Thanks

alessandrofrancesconi avatar Feb 01 '20 14:02 alessandrofrancesconi

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.

frostieDE avatar May 05 '20 10:05 frostieDE