0
votes

https://docs.microsoft.com/en-us/aspnet/core/signalr/hubs?view=aspnetcore-3.1#create-and-use-hubs says "Create a hub by declaring a class that inherits from Hub, and add public methods to it. Clients can call methods that are defined as public.".

I would like to have public methods in my hub (callable from other places in the server), that are not exposed to the clients. Surely there must exist an attribute to make public methods not callable? Or is this really not supported?

Thanks.

1
I'm not allowed to comment, so sorry for posting this as an answer. Contrary to @Brennan, you can call Hub methods from elsewhere on the server, by injecting an instance of IHubContext. > In ASP.NET Core SignalR, you can access an instance of IHubContext via > dependency injection. You can inject an instance of IHubContext into a > controller, middleware, or other DI service. Use the instance to send > messages to clients. Here are the docs. - Paul Guz

1 Answers

0
votes

You can't call methods on the hub from other places in your server. The Hub methods are only for the client to call. You also should not be manually creating or storing Hub instances, Hubs are created/controlled/destroyed by the SignalR library.