Signalr IConnectionIdGenerator not found in SignalR 1.0rc2 release

帅比萌擦擦* 提交于 2019-12-12 10:13:57

问题


I used to implement my own connection id generator with the following code:

public class MyConnectionFactory : IConnectionIdGenerator
{
    public string GenerateConnectionId(IRequest request)
    {
        return MyUserManager.Instance.CurrentUserID.ToString();
    }
}

This was working fine with SignalR 0.5.3 release but after updating to SignalR 1.0rc2 release the namespace or class name is not found. Also, I am not able to find any note on this breaking change here https://github.com/SignalR/SignalR/blob/master/ReleaseNotes.md Can you help me fixing this issue?


回答1:


This is gone indeed and there is no direct replacement as you're supposed to do the user/connection mapping manually now.

I solved it using a HubPipelineModule and setting up a group for all connections of that user.

public class AuthenticationHubPipelineModule : HubPipelineModule
{
    protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
    {
        var id = MyUserManager.Instance.CurrentUserID.ToString();

        context.Hub.Groups.Add(context.Hub.Context.ConnectionId, id);

        return base.OnBeforeIncoming(context);
    }
}

When you then want to reach out to the user, you can just send it to that group like this:

var context = GlobalHost.ConnectionManager.GetHubContext<YourHub>();
context.Clients.Group(userId).yourCallbackMethod();

Hope this helps, Yves



来源:https://stackoverflow.com/questions/14725051/signalr-iconnectionidgenerator-not-found-in-signalr-1-0rc2-release

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!