Skip to content
Discussion options

You must be logged in to vote

As Timothy said, neither form is supported - there is no [Url] attribute in Refit, and the base address is not read from interface metadata or appsettings automatically. The base address is supplied when the client is created.

For your "many clients, base addresses from appsettings.json" scenario, use IHttpClientFactory + DI. That is the idiomatic way and avoids hand-rolled reflection.

appsettings.json:

{
  "Services": {
    "UserApi": "http://localhost:10000/api/user",
    "OrderApi": "http://localhost:10001/api/order"
  }
}

Registration:

services.AddRefitClient<IUserClient>()
    .ConfigureHttpClient((sp, c) =>
        c.BaseAddress = new Uri(
            sp.GetRequiredService<IConfigur…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@LimOpsx
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by glennawatson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants