3

We're building an application composed of mostly stateless microservices on Azure Service Fabric. One of the artifacts of service fabric is that the naming service returns you the endpoint for one of the instances of a service.

If the client fails to communicate with that service, it needs to go back to the naming service, get the endpoint for another instance and try again.

As I don't want every developer having to do this, I created a DelegatingHandler for this. However, the naming service takes a string to identify the service. Setting this identifier as a property on the handler makes it stateful and therefore the resulting HttpClient object can no longer be shared to call different services.

Because the handlers are private to the HttpClient class, I cannot change the property of an existing handler.

Another annoying thing is that HttpClient enforces the use of the BaseAddress property when using relative URLs.

So should delegating handlers not be used for anything that requires state (like service discovery)? Is there a better way to solve this?

MvdD
  • 22,082
  • 8
  • 65
  • 93

0 Answers0