5

am working on chat application, using signal R.

I was wondering about when to use multiple hubs in signal r, what are the advantages, to use multiple hubs, or to use single hub is good approach?

bilal
  • 648
  • 8
  • 26

3 Answers3

5

Per https://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-server#multiplehubs

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

Therefore, it is simply a matter of deciding if you want to use multiple hubs to organize your code/functionality. OOP principals certainly apply, but it's a logical decision you have to make.

Alex Dresko
  • 5,179
  • 3
  • 37
  • 57
3

You should create a different one if it would serve a different purpose from your existing ones. You should follow the same approach you normally do in OOP - that is, a class should represent a logical unit.

Balázs
  • 2,929
  • 2
  • 19
  • 34
3

Every new hub/connection you open will keep a live connection to the server. Each of those consuming network and processing resources. This is something important on mobile devices to prevent battery drain. I would keep a single hub whenever is possible. A single hub on the server can be used from different logical parts or layers of your code.

xleon
  • 6,201
  • 3
  • 36
  • 52