Is there a published pattern for using the async client in a asp.net core website? Should I register the OctopusAsyncClient as a singleton in DI, or maybe the OctopusServerEndpoint and then create a OctopusAsyncClient object from that endpoint for each call?
Is the OctopusAsyncClient or OctopusServerEndpoint object thread safe?
We don’t have a published pattern for this, but I can give you some more information to help you make a decision.
OctopusServerEndpoint should be thread safe.
OctopusAsyncClient is mostly thread safe. At a glance, the only things in its implementation is the use of the
cookieContainer. This is used when using the
SignIn method to authenticate with a username and password. If you are using an API Key to authenticate, then you bypass this limitation and I would expect it to be thread safe.
OctopusAsyncRepository and other
*Repository classes should be thread safe. These classes don’t usually have any extra state, and therefore don’t introduce any extra threading concerns beyond those present in
All that being said, I would not expect that creating separate instances of these classes for each dependency would introduce a significant cost, especially when compared to the IO involved in actually performing requests with the client. The only downside to creating a new client for each dependency is that it will not be able to cache the root document, which means you’ll end up with one extra request per instance, that you could save by using a single instance of the client.
Hope that helps!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.