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

Allow access to injected services during DI registration of DaprClient #1288

Closed
WhitWaldo opened this issue May 15, 2024 · 1 comment · Fixed by #1289
Closed

Allow access to injected services during DI registration of DaprClient #1288

WhitWaldo opened this issue May 15, 2024 · 1 comment · Fixed by #1289
Assignees
Labels
kind/enhancement New feature or request
Milestone

Comments

@WhitWaldo
Copy link
Contributor

Describe the feature

Today, an extension method enables easy DI registration of the DaprClient on an IServiceCollection, but it doesn't allow for an IServiceProvider to be passed in so values can be pulled from injected dependencies. Having this option has some benefits - for example, say I'm passing in configuration values via a JSON file or via environment variables. I could trivially register the values for either in the service's IConfiguration (e.g. services.Configuration.AddEnvironmentVariables(); and recall via configuration.GetValue<string>("DAPR_HTTP_ENDPOINT"), but only if I can get an instance of the IConfiguration to get the values out of.

Where today, we might use the following:

var builder = WebApplication.CreateBuilder(args);
var httpEndpoint = Environment.GetEnvironmentVariable("DAPR_HTTP_ENDPOINT");
builder.Services.AddDaprClient(opt => {
  opt.UseHttpEndpoint(httpEndpoint);
});

This additional overload would also enable the following:

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables("DAPR_");
builder.Services.AddDaprClient((serviceProvider, daprClient) => {
  var configuration = serviceProvider.GetRequiredService<IConfiguration>();
  var httpEndpoint = configuration.GetValue<string>("HTTP_ENDPOINT");
  daprClient.UseHttpEndpoint(httpEndpoint);
});

I use it here to inject a value out of environment variables, but it could just as easily be a secret out of an Azure Key Vault instance or a value passed from Azure App Configuration or anything else that's registered in the application.

Release Note

RELEASE NOTE: ADD DaprClient dependency injection extension overload added to facilitate registration with dependencies

@WhitWaldo
Copy link
Contributor Author

/assign

@philliphoff philliphoff added this to the v1.14 milestone Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants