首页 > 解决方案 > Using SignalR via reflection

问题描述

I am developing an asp.net core 3.1 application that loads up an assembly using Application Parts and reflection. This plugin assembly is also an asp.net core 3.1 application which is all working fine except it also has SignalR functionality within it. In the host application I have the service registered in Startup.cs like this:-

services.AddSignalR();

In the Configure method I would normally have something like this:-

endpoints.MapHub<MyHub>("/myHub");

But MyHub is a class from the plugin assembly. How can I map the hub when it could be of any type? I don't want to have this MyHub class in the host application, it can only be in the plugin application.

标签: asp.netasp.net-coresignalr

解决方案


在您的解决方案中,您可以创建.NET Core Library引用主项目的新项目。

在库项目中,您可以添加此 Nuget 包:

Microsoft.AspNetCore.SignalR.Core

然后,从那里创建您的 Hub 类并从Startup该类映射它。


推荐阅读