本文介绍了如何在.NET Core中使用IUserIdProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
本文介绍了如何使用IUserIdProvider接口.它显示了如何使用GlobalHost来使SignalR使用您的用户ID提供程序.但是SignalR for .Net Core没有GlobalHost.什么是替代品?
This article describes using IUserIdProvider interface. It shows how you can use GlobalHost to make SignalR use you user ID provider. But SignalR for .Net Core does not have GlobalHost. What is the replacement?
推荐答案
您需要实现 IUserIdProvider
.
You need to implement IUserIdProvider
.
public class MyCustomProvider : IUserIdProvider
{
public string GetUserId(HubConnectionContext connection)
{
...
}
}
然后您需要在 Startup
中注册它以进行依赖项注入:
Then you need to register it in Startup
for dependency injection:
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
services.AddSingleton<IUserIdProvider, MyCustomProvider>();
}
然后 SignalR
将在诸如 HubEndPoint.OnConnectedAsync()
Then SignalR
will use your UserIdProvider
in such events like HubEndPoint.OnConnectedAsync()
这篇关于如何在.NET Core中使用IUserIdProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!