BaseClient's HttpClientInitializer property is private set, making it impossible to change cred after client is initialized, forcing unneeded recreations. Any workaround? #2064
Labels
priority: p3
Desirable enhancement or fix. May not be included in next release.
type: question
Request for information or clarification. Not an issue.
We have stored users tokens (both access and refresh) in our database and handle our own refresh logic. So we use
GoogleCredential.FromAccessToken
to authenticate the clients.I'm trying to implement DI pattern for various clients (
CalendarService
,GmailService
etc) as they're used a lot within the same class across many methods. DI would make them reusable and easy to manage.However, the
HttpClientInitializer
can only be set at construction time. The problem is that our service layer codes all use DI. It is not possible for us to set user at DI constructor injection time, so we need to rely on user IDs etc passed to our service methods to retrieve the correct users' tokens and set the credentials on these clients.Because
HttpClientInitializer
cannot be set after client creation, it forces us to recreate clients repeatedly.I suspect this design may have something to do with thread safety, but since Google has batch support, I don't think running multiple clients in parallel is a good pattern, especially considering the fact that Google has various limits on per user/api/project calls.
Is there a way to make DI work in my scenario?
Would you consider making the
HttpClientInitializer
property public settable?It's a bit of a pain as we're trying to build a service that works with both MS Graph and Google, and MS's
GraphServiceClient
doesn't have such a restriction, so we have to treat the Google side differently. 😄The text was updated successfully, but these errors were encountered: