问题
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