如何在类库项目中使用SignalR Hub

问题描述 投票:0回答:1

如何在类库项目中使用Signalr Hub类? 我没有看到可能对 Hub 的引用。

在应用程序项目(类库)中我无权访问此类 enter image description here

在引用应用程序项目的 Web 项目中,我可以访问 Hub enter image description here

如何在Application项目中访问它?

enter image description here

应用程序csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentValidation" Version="11.9.0" />
    <PackageReference Include="MediatR" Version="12.2.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Bidnest.Persistance\Bidnest.Persistance.csproj" />
  </ItemGroup>

</Project>
c# asp.net-core domain-driven-design mediatr
1个回答
0
投票

如果我们需要在

Class Library (.net core)
项目中定义signalr hub,我们必须安装
Microsoft.AspNetCore.SignalR.Core
包。

众所周知,asp.net Core SignalR 包已默认集成到 asp.net Core 7/8 Web 应用程序中。

所以如果我们想在

Class Library
中使用它,我们必须手动安装它。

我之前写过一个repo,这里是你可以参考的链接https://github.com/Jason446620/AspNetCore7

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.