Azure / azure-functions-signalrservice-extension

Azure Functions bindings for SignalR Service. Project moved to https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/signalr/Microsoft.Azure.WebJobs.Extensions.SignalRService .
MIT License
97 stars 47 forks source link

Multiple Hubs per Function with OnConnected Method #194

Closed phantomcosmonaut closed 3 years ago

phantomcosmonaut commented 3 years ago

I have two class-based model hubs exposed by the same Function, however The OnConnected method name is problematic because a function cannot have duplicate names and I cannot use binding or I get the following error:

The 'OnConnected' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'OnConnected'. Microsoft.Azure.WebJobs.Extensions.SignalRService: SignalRTriggerAttribute must use parameterless constructor in class based model.

class FooHub : ServerlessHub
{
  [FunctionName(nameof(NegotiateFoo))]
  public Task<SignalRConnectionInfo> NegotiateFoo([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest httpRequest, ILogger logger)
  {
    ...
  }

  [FunctionName(nameof(OnConnected))]
  public async Task OnConnected([SignalRTrigger] InvocationContext invocationContext, ILogger logger)
  {
    ...
  }
}

class BarHub : ServerlessHub
{
  [FunctionName(nameof(NegotiateBar))]
  public Task<SignalRConnectionInfo> NegotiateBar([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest httpRequest, ILogger logger)
  {
    ...
  }

  [FunctionName(nameof(OnConnected))]
  public async Task OnConnected([SignalRTrigger] InvocationContext invocationContext, ILogger logger)
  {
    ...
  }
}
Y-Sindo commented 3 years ago

You can change [FunctionName(nameof(OnConnected))] to other names, as long as the C# function name is OnConnected

phantomcosmonaut commented 3 years ago

oh wow, thought the auto binding was coming from function name. Thanks!