0

This is not a question about accessing a REST API over a websocket.

I have a REST API which already exists and I'm looking to add websockets that I can send an 'eventId' over in a style similar to google cloud messaging / firebase. This eventId can then be used by clients to access the needed APIs.

The question is where do I define the "ClientManager"?

Currently I'm instantiating the ClientManager in 'Configure' and below am accepting sockets and echoing their data back as a test (as described here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/websockets?view=aspnetcore-3.1). I'm not sure how to access this instance from elsewhere in the webapp. It seems it should be defined globally. I've found some information on services.AddSingleton but have been unable to get this to work.

karezza
  • 586
  • 5
  • 13

1 Answers1

0

The answer can be found here: ASP.NET Core initialize singleton after configuring DI

You declare the singleton in ConfigureServices & then pass it as a parameter to Configure. The link above gives a few other techniques all with the same result.

karezza
  • 586
  • 5
  • 13