C# 在启动ASP.NET Core 3中配置通用集线器
我有一个通用集线器:C# 在启动ASP.NET Core 3中配置通用集线器,c#,asp.net,asp.net-core,signalr,asp.net-core-3.0,C#,Asp.net,Asp.net Core,Signalr,Asp.net Core 3.0,我有一个通用集线器: public类sendRequestToUserSignal其中T:class其中HubContext:Hub { 专用只读IUserConnectionManager用户连接管理器; 私有只读IHubContext-hubContext; public SendRequestToUserSignalR(IUserConnectionManager用户连接管理器,IHubContext hubContext) { this.userConnectionManager=use
public类sendRequestToUserSignal其中T:class其中HubContext:Hub
{
专用只读IUserConnectionManager用户连接管理器;
私有只读IHubContext-hubContext;
public SendRequestToUserSignalR(IUserConnectionManager用户连接管理器,IHubContext hubContext)
{
this.userConnectionManager=userConnectionManager;
this.hubContext=hubContext;
}
}
我需要在启动时设置它:
app.usesigner(路由=>
{
routes.MapHub(“/sendRequest”);
});
但它不起作用,我得到一个错误:
使用泛型类型“SendRequestToUserSignal”需要2个类型参数
如何解决此问题?对我来说,您的配置完全错误 您不需要将泛型类定义为集线器:
public class SendRequestToUserSignalR : Hub
{
public SendRequestToUserSignalR(...services)
{
// code goes here...
}
}
在ConfigureServices
方法中,您需要启动服务:
services.AddSignalR();
在Configure
方法中,将该中心映射到UseEndpoints
方法中:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapHub<SendRequestToUserSignalR>("/sendRequest");
});
app.UseEndpoints(端点=>
{
endpoints.MapControllerRoute(
名称:“默认”,
模式:“{controller=Home}/{action=Index}/{id?}”);
endpoints.MapHub(“/sendRequest”);
});
注意:
app.usesigner
方法在asp.net核心版本3.x中已过时对我来说,您的配置完全错误
您不需要将泛型类定义为集线器:
public class SendRequestToUserSignalR : Hub
{
public SendRequestToUserSignalR(...services)
{
// code goes here...
}
}
在ConfigureServices
方法中,您需要启动服务:
services.AddSignalR();
在Configure
方法中,将该中心映射到UseEndpoints
方法中:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapHub<SendRequestToUserSignalR>("/sendRequest");
});
app.UseEndpoints(端点=>
{
endpoints.MapControllerRoute(
名称:“默认”,
模式:“{controller=Home}/{action=Index}/{id?}”);
endpoints.MapHub(“/sendRequest”);
});
注意:
app.usesignar
方法在asp.net core 3.x版中已过时在hub具有依赖项之前,即在通过SimpleInjector或其他DI容器创建的MyApi上,此方法非常有效。在hub具有依赖项之前,即,在通过SimpleInjector或其他DI容器创建的MyApi上。