Closed leonibr closed 3 years ago
Which method would the params such as baseAddress
, configurer
and requestModifier
be passed to?
Sorry for the delay,. I think I didn't quite explain correctly.
I usually create several clients like UserClient
, ProfileClient
and so on, and those clients share a common configuration settings like baseAddress
and some common HttpMessageHandlers
.
So there is no way to pass multiple clients registration that will share some common configuration?
I don't think you should create a new API for this, I thought there was something out of docs for this sugar, but thanks.
There isn't currently. It wouldn't be hard to add something I think: you'd probably want to turn the API around a bit and call:
services.AddHttpClient(...).AddRestEaseClient<T1>().AddRestEaseClient<T2>()...;
You're basically just splitting this code out into its own extension method on IHttpClientBuilder
.
You wouldn't be able to pass in a baseAddress
or HttpMessageHandler
to AddRestEaseClient
of course: those need to be registered with the HttpClient
, so you'd need to configure them there.
ok, I see your point. Thank you again.
Reopening, as I think this is probably something worth implementing.
I'm new to this library but I've created a factory class where I pass in the IApi type I need and then return the RestClient.For<T>(...)
and handle all of my logic e.g. adding the Bearer token etc. so I can keep my code DRY. The solution above would really help with that, unless there's another way already to globally add adding headers?
This issue won't be relevant to you if you're configuring a RestEase interface after constructing it, before returning it. It's just about if you're using HttpClientFactory and IServiceProvider.
If you've got other questions, please open another issue. Thanks!
Hi, Is there a way that
AddRestEaseClient
could register multiple interfaces, something like:Thank you for your time