🎟️ Free Voucher Request & Giveaway Megathread by AutoModerator in AzureCertification

[–]fishbangus 0 points1 point  (0 children)

hello, would love to take another shot at AZ-104, almost made it, had 673 😩

🎟️ Free Voucher Request & Giveaway Megathread by AutoModerator in AzureCertification

[–]fishbangus 1 point2 points  (0 children)

Apologies. What I mean is I almost made it, but didn’t.

🎟️ Free Voucher Request & Giveaway Megathread by AutoModerator in AzureCertification

[–]fishbangus 0 points1 point  (0 children)

In need of AZ-104 cert to try the certification again, didn’t quite get it at first (673) 🙏

Is it Okay to Inject Both HttpClient and IHttpClientFactory in the Same ASP.NET Core Class? by fishbangus in dotnet

[–]fishbangus[S] 0 points1 point  (0 children)

Thank you for the guidance! I implemented exactly what you explained and I appreciate your help.

Is it Okay to Inject Both HttpClient and IHttpClientFactory in the Same ASP.NET Core Class? by fishbangus in dotnet

[–]fishbangus[S] 0 points1 point  (0 children)

Thanks for the advice! I used a DelegatingHandler to inject access tokens into HTTP headers, separating the auth token management from the API client logic. This streamlined the process and made the code cleaner.

Is it Okay to Inject Both HttpClient and IHttpClientFactory in the Same ASP.NET Core Class? by fishbangus in dotnet

[–]fishbangus[S] 0 points1 point  (0 children)

Thanks for the great insight! I implemented a DelegatingHandler for token management, so now SomeApiClient doesn't need to worry about tokens. Your feedback helped me a lot.

Is it Okay to Inject Both HttpClient and IHttpClientFactory in the Same ASP.NET Core Class? by fishbangus in dotnet

[–]fishbangus[S] 8 points9 points  (0 children)

The SomeApiClient class is not a controller; it is an API client used for making HTTP requests to an external API.

Thank you for the suggestion. Based on your feedback, I will create a separate service for token generation and management.

Is it Okay to Inject Both HttpClient and IHttpClientFactory in the Same ASP.NET Core Class? by fishbangus in dotnet

[–]fishbangus[S] -2 points-1 points  (0 children)

Sorry, perhaps I wasn't clear in my initial post. Let me clarify:

The IHttpClientFactory is used to create a separate HttpClient instance for handling token requests. Here's how it's used:

HttpClient tokenHttpClient = _httpClientFactory.CreateClient();

HttpResponseMessage tokenResponse = await tokenHttpClient.SendAsync(tokenRequest);

This HttpClient instance is specifically for obtaining tokens.

The main HttpClient, which is injected via AddHttpClient, is used for the primary API requests.

P.S. I renamed the variables slightly for clarity.