postmark-dotnet icon indicating copy to clipboard operation
postmark-dotnet copied to clipboard

Non-static client factory

Open mburumaxwell opened this issue 4 years ago • 9 comments

Microsoft advises that we should IHttpClientFactory to implement resilient HTTP requests (see docs). For this to happen, the HttpClient needs to be provided when creating instances of PostmarkClient or PostmarkAdminClient.

In this PR, the static client factory is replaced with an optional ISimpleHttpClient parameter. This works for scenarios where the injection of HttpClient instances is (and is not) preferred.

mburumaxwell avatar Oct 01 '21 06:10 mburumaxwell

@vladsandu any chance you can have a look?

mburumaxwell avatar Nov 11 '21 08:11 mburumaxwell

Hey @mburumaxwell sorry for the delay -- we'll take a look. Vlad no longer works at Wildbit.

jchoca avatar Nov 11 '21 15:11 jchoca

@mburumaxwell is there a specific problem the current interface/design is causing for you that you are trying to solve with this PR?

While it is true that HttpClient should be re-used, and it is also true that MS docs currently suggest creating clients from IHttpClientFactory, I'm not sure this change is worth the risk imposed, and the testing effort that would be required.

jchoca avatar Nov 11 '21 17:11 jchoca

@jchoca the intention is to inject the client using instances form IHttpClientFactory which brings a couple of benefits, including logging. I just thought it would be better to do a different PR for the dependency injection scenario.

mburumaxwell avatar Nov 11 '21 17:11 mburumaxwell

What would that other PR consist of?

jchoca avatar Nov 11 '21 17:11 jchoca

@mburumaxwell - ClientFactory is already a static property, you are free to change it if you'd like to provide a different factory method for creating the client.

Archanian avatar Nov 11 '21 17:11 Archanian

Unfortunately, that doesn't work well with a dependency injection.

It requires a lot of effort to setup get services.AddHttpClient<PostmarkClient>(...) working with it.

mburumaxwell avatar Nov 11 '21 17:11 mburumaxwell

Fair enough, I understand your concern. However, conformance to a DI mechanism is not a strong enough reason to make this change.

Archanian avatar Nov 11 '21 18:11 Archanian

@Archanian could you explain how you arrived at the decision for "not a strong enough reason"? For clarity purposes, what would break or not work as expected?

mburumaxwell avatar Nov 14 '21 20:11 mburumaxwell