Using PostConfigure to change client addresses on injection
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 836
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 7
Description
Is there a way to use PostConfigure so that all clients in a service created through dependency injection will have their address changed based on a setting? I am modifying an extension method with no parameters called by folks after calling AddGrpcClient.
I want to avoid having the service owners using this extension make any code changes if at all possible.
in Startup.cs ConfigureServices method:
`services.AddGrpcClient(...).**EXTENSION_METHOD**`
From the extension method, I want to check an environment variable flag and then change the address whenever the flag is set to true.
Right now in my extension method, I am trying to use PostConfigure\ to do the job, but from my container logs it looks like the PostConfigure is never executed, and the calls are still being made to the original address that was passed in to the Action\ configureClient parameter when AddGrpcClient was called.
currently doing something like this:
```
clientBuilder.Services.PostConfigure(o =>
{
Console.WriteLine("PostConfigure GrpcClientFactoryOptions");
if (flag) {
o.Address = OTHER_ADDRESS
}
});
```
Is my approach possible, and if it is, where I am going wrong in my execution?
Thanks for any insights you can provide!
Contributor guide
Research direction
Start in Startup.cs ConfigureServices with the AddGrpcClient registration and follow how GrpcClientFactoryOptions is configured and post-configured through dependency injection. Verify whether the extension method can override the client address from the environment flag without changes by service owners. Done means establishing the supported behavior and documenting or validating the resulting address selection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100