You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
I have a use-case of message forwarding from a different event bus. This event bus can dispatch generic-typed events as well as an ability to handle all the events in a single general handler, in which case the dispatched event will be passed as an object.
// e here is an `object` which cannot be dispatched to a generic AsyncMessageBus handler
DomainEvents.RegisterGeneralHandler(e => AsyncMessageBus.Default.PublishAsync(e));
An easy fix here would be to add an overload that accepts object as a msg argument and just msg.GetType(). Probably it is not needed in UniTaskPubSub or maybe there's a better way to do this, but right now I'm not sure how to deal with this issue without Reflection.
The text was updated successfully, but these errors were encountered:
Ok, I'm going to consider adding a Non-Generic version of Publish.
However, the current Generic version of Publish does not have boxing allocation, while the Non-Generic version definitely has boxing and will degrade performance compared to the Generic version.
--
Another way to do msg.GetType() might be to cast the object.
Again, most likely it's not worth it. As you said, it will have performance implications, but more than that it adds some sematics which might be not clear:
Does this code mean that Handler will handle any possible message? Looks like it should if Non-Generic publish is introduced. And after that the question of polymorphic dispatch can arise. Similar thing is done in MediatR
Hi again,
I have a use-case of message forwarding from a different event bus. This event bus can dispatch generic-typed events as well as an ability to handle all the events in a single general handler, in which case the dispatched event will be passed as an
object
.An easy fix here would be to add an overload that accepts
object
as amsg
argument and justmsg.GetType()
. Probably it is not needed in UniTaskPubSub or maybe there's a better way to do this, but right now I'm not sure how to deal with this issue without Reflection.The text was updated successfully, but these errors were encountered: