Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
Hi,
I'm using PowerBIClient in my ASP.NET 5 web application. Currently new instance of PowerBIClient (Microsoft.PowerBI.Api 3.22.0) is made for every request. I've noticed that internally PowerBIClient creates HttpClient and from what I know this is not the best practice. I try to find a way to inject my own HttpClient created with IHttpClientFactory. There is a constructor overload in PowerBIClient that takes HttpClientHandler. Unfortunately I'm not able to get it from IHttpClientFactory.
I'm experimenting with inheritance to access HttpClient property and override it with my own one. It works quite well but ServiceClient<> (which is part of PowerBIClient) creates HttpClient in its primary constructor and I need to dispose it first. Is there any better option?
internal class PowerBIClientWrapper : PowerBIClient
{
public PowerBIClientWrapper(
Uri baseUri,
ServiceClientCredentials credentials,
HttpClient httpClient) : base(baseUri, credentials)
{
HttpClient?.Dispose();
FirstMessageHandler = null;
HttpClientHandler = null;
HttpClient = httpClient;
}
}
@Anonymous, yes, I found two potential solutions for that. You can either override internal PowerBIClient's HttpClient property or register PowerBIClient as a singleton (with appropirate SocketsHttpHandler configuration). I described both approaches in details on my blog: https://brokul.dev/powerbiclient-and-socket-exhaustion-in-asp-net-core-app/
@Anonymous did you find a solution? I am interested in this as well. Thank you
Hi @Anonymous ,
See if this blog helps:
https://blog.bennymichielsen.be/2017/11/09/powerbi-with-net-core/
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Check out the July 2026 Power BI update to learn about new features.
Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.
| User | Count |
|---|---|
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |