Hello,
I need to send messages to my Server Events client that use generic type DTO.
For example:
MyMessage<MyTypeA>
MyMessage<MyTypeB>
I’m sending those to the client using this
ServerEvents.NotifyUserName(name, selector, message, channel)
where selector looks like this: “cmd.MyMessage`1[[MyTypeA]]” and it is constructed from adding “cmd.” to message full type name (with generic type) so that it can be used with named receiver class on the client.
On the client I have a named receiver class that looks like this:
class MyReceiver : ServerEventReceiver
{
public Task ProcessA(MyMessage<MyTypeA> message)
{ . . . }
public Task ProcessB(MyMessage<MyTypeB> message)
{ . . . }
}
However these methods never get executed.
I looked into this code in the framework:
internal class ReceiverExec<T>
{
public static void Reset()
{
. . .
var methods = typeof(T).GetMethodInfos().Where(x => x.IsPublic && !x.IsStatic);
foreach (var mi in methods)
{
. . .
var actionName = mi.Name;
. . .
var requestType = args[0].ParameterType;
var execCtx = new ReceiverExecContext
{
Id = ReceiverExecContext.Key(actionName, requestType.GetOperationName()),
ServiceType = typeof(T),
RequestType = requestType,
Method = mi.Name
};
}
}
}
The UrlExtensions.GetOperationName(this Type type) has code that removes generic type name from operation name.
Is there anything we can do to support generic type messages / requests? Perhaps the ReceiverExecContext.Key generation can use a delegate?
What do you think?