I would like my ASP.NET Core application to send messages to a Azure Service Bus.
In Microsoft's article Best Practices for performance improvements using Service Bus Messaging they argue that you should re-use instances of clients.
It is recommended that you do not close messaging factories or queue, topic, and subscription clients after you send a message, and then re-create them when you send the next message.
So I take that as I should not instantiate a new instance of the client (TopicClient
or QueueClient
) inside my controller using the new
keyword.
I guess that I should use dependency injection in ASP.NET Core.
Should I directly inject a TopicClient
/QueueClient
or should I create an own class that wraps an instance of the client and expose a SendAsync
method?
When registering the service with dependency injector should I register it as a singleton?