Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding instance-based CreateInvokableHttpClient #1319

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

WhitWaldo
Copy link
Contributor

Description

After installing the Dapr.Client NuGet package, there exists a method on a DaprClient called CreateInvokeHttpClient which accepts an appId, a daprEndpoint and a daprApiToken argument and produces an HttpClient that can be used to send well-formed HTTP requests to other applications accessible by Dapr.

After installing the Dapr.Client.AspNetCore package, developer get some extensions that simplify the registration of a DaprClient so it can be injected into downstream classes. This is great because especially if the developer is using a non-standard HTTP endpoint or is utilizing the Dapr API token, either can be retrieved in one place, registered in the Dapr client and later uses of the client can just be invoked - no need to keep retrieving those for new invocations.

I'd like to marry the two ideas - because CreateInvokeHttpClient is a static method on a DaprClient, it doesn't contain any of the properties set on a DI-registered DaprClient, so each invocation requires that I retrieve the daprApiToken and daprEndpoint values all over again, which simply doesn't make sense as I've already done it once at registration for all other instance-based operations.

This PR does just that - it takes the implementation of the static method and puts it into the DaprClient instance, pulling from the existing apiTokenHeader on the instance to populate the daprApiToken, pulling the endpoint from the instance's httpEndpoint value and accepting only an appId argument so as to specify the ID of the Dapr app to connect to and place in the resulting URI.

This way, a developer can register an instance of a DaprClient using a configured Dapr API token and non-standard HTTP endpoint once, and build an HttpClient from that instance that is already configured with these values when they want to invoke other Dapr endpoints without using the service invocation methods (enabling with the instance what they can already do with the static approach, minus the configured values).

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close:

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • [N/A] Extended the documentation

…ch like the static method, but using the DaprApiToken already persisted (meaning this can be created from the injected DaprClient instance)

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
…g unit tests for static method

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
…th the DaprClient instance. If a developer wants to opt-out, they should use the static invocation method instead.

Updated unit tests to exclude invalid endpoints as that's handled by the DaprClient instead now.

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
@WhitWaldo WhitWaldo requested review from a team as code owners July 4, 2024 09:07
@philliphoff philliphoff added this to the v1.15 milestone Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants