silentpartnersoftware/Keycloak.Net

Add ability to inject HttpClient instance

Closed this issue · 4 comments

Add the ability to inject an HttpClient instance. This library is a no-go for my team without this capability.

Hi @goldsam, could you please provide some more information? This library is built using Flurl which provides a wrapper for HttpClient, and manages the HttpClient lifecycle, etc.

It would be a significant design change to move this project from Flurl to a standard HttpClient, so this issue is likely out of scope, unless Flurl has support to configure it with an existing HttpClient.

I understand. Why does HttpClient need to be wrapped? this is the platform standard client. Preventing me from injecting my own instance flies in the face of well established conventions - specifically constructor injection.

I see Flurl has an IFlurlClientFactory abstraction. Allowing an instance of this interface to be injected into the client constructor would satisfy my requirements.

Hi @goldsam,

I see that you opened an issue on the Flurl project yesterday asking for some more information about the goals of Flurl. I see it has since been deleted, so hopefully you got a satisfactory answer.

As for why it is used in this project, as you can likely see this project was forked from an earlier project, and we took over maintenance of the fork in mid-2023, so I cannot really speak to why it was originally chosen, as Flurl has been a dependency for this project long before we started maintaining it.

With that said, as with many open-source projects we welcome contributions from the community, so, if you would like to be able to inject an existing HttpClient instance via the Factory interface you identified you are welcome to open a Pull Request. Please keep in mind when implementing this change should be backwards compatible with the existing implementation, i.e. it should be optional to inject an HttpClient and your change should not require users to manage their own HttpClient if they do not want to.

If you do open a PR please let me know so that it doesn't get missed,
Thanks.

I've found that it was easier to just NSwag to code generate a client from a generated Keycloak OpenAPI spec. This approach is easier to keep up to date and is considerably more flexible. Thanks though.