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

Using PostConfigure to change client addresses on injection #2390

Open
evanwhitehouse opened this issue Mar 15, 2024 · 0 comments
Open

Using PostConfigure to change client addresses on injection #2390

evanwhitehouse opened this issue Mar 15, 2024 · 0 comments
Labels
question Further information is requested

Comments

@evanwhitehouse
Copy link

evanwhitehouse commented Mar 15, 2024

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<CLIENT_TYPE>(...).**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<GrpcClientFactoryOptions> 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<GrpcClientFactoryOptions> configureClient parameter when AddGrpcClient was called.

currently doing something like this:

clientBuilder.Services.PostConfigure<GrpcClientFactoryOptions>(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!

@evanwhitehouse evanwhitehouse added the question Further information is requested label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant