SignalR Hub 的最佳使用 [英] Best use of SignalR Hub

查看:29
本文介绍了SignalR Hub 的最佳使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有不同的部分,如产品、人员、供应商等,它们是我在 Db 中定义为表的实体,每个部分都有单独的页面和自己的逻辑,用于根据数据库变化.另外,我有一些向用户和组发送消息的一般规则.在此应用程序中,用户可以与他们聊天.

In my app, I have different parts, like Products, People, Suppliers, etc that they are entities which I defined as a Table in Db, and each part has separated page and its own logic for instant client update according to the Database changes. Also, I have some general rules for sending messages to Users and Groups. In this application, users can chat with them.

但是,我真的无法决定如何在我的应用程序中实现这些?我需要多少个集线器?单一枢纽和不同方法还是多个枢纽?

However, I really can't decide how should I implement these in my application? How many hubs do I need? Single hub and different methods or multiple hubs?

我认为每个实体都有多个中心,因为它有一个单独的页面,一个中心用于一般规则,另一个用于聊天,但我不知道这是一个好主意吗?

I think I have multiple hubs for each entity because it has a separate page and one hub for general rules and another for chat, but I don't know is it a good idea or not?

谢谢

推荐答案

根据 docs 没有性能差异.

According to the docs there is no performance difference.

使用它来形成您自己的决定,因为您知道您的所有要求.有些人会说是,有些人会说不是.

Use that to form your own decision as you know all of your requirements. Some people will say yes, some will so no.

这是来自该链接的信息片段:

Here is a snippet of info from that link:

您可以在一个应用程序中定义多个 Hub 类.当你这样做时,连接是共享的,但组是分开的:

You can define multiple Hub classes in an application. When you do that, the connection is shared but groups are separate:

所有客户端将使用相同的 URL 与您的服务建立 SignalR 连接(/signalr"或您的自定义 URL,如果您指定了一个),并且该连接用于服务定义的所有集线器.

All clients will use the same URL to establish a SignalR connection with your service ("/signalr" or your custom URL if you specified one), and that connection is used for all Hubs defined by the service.

与在单个类中定义所有 Hub 功能相比,多个 Hub 的性能没有差异.

There is no performance difference for multiple Hubs compared to defining all Hub functionality in a single class.

这篇关于SignalR Hub 的最佳使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆