RestLess icon indicating copy to clipboard operation
RestLess copied to clipboard

Updated RestRequest to use http client factory rather than http client directly

Open nicklundin08 opened this issue 6 years ago • 1 comments

Currently the RestClients generated hold onto the http client for the lifecycle of the client. This change would allow the user to pass in something else that manages the lifecycle of the http client

e.g. IHttpClientFactory https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-2.2.

https://github.com/letsar/RestLess/issues/2

nicklundin08 avatar May 28 '19 02:05 nicklundin08

After sleeping on this I realize the problems my PR is trying to solve isn't quite clear. I've expanded on this a bit here

My thought process behind using Func<HttpClient> rather than the IHttpClientFactory directly was that the library would not have to add the dependency on this package (which requires .net standard 2.0). However, I think one of the downfalls of this approach is that the client can easily shoot themselves in the foot with Func<HttpClient>

Perhaps a better solution would be to have a separate package (RestLess.Extensions.Http) or something like that that has an entry point (maybe RestClient becomes a partial class that also exists in this package so that the apis look similar from the clients perspective) that supports the interface directly (but under the hood the rest request and all the other classes still use Func<HttpClient> that way they can support using either a single instance of HttpClient or using IHttpClientFactory to create an HttpClient for each request).

Ill think about that for a little bit and I may end up editing the PR, but in the meantime if you have any feedback I'd love to hear it!

nicklundin08 avatar May 28 '19 17:05 nicklundin08