Skip to content

Missing code in the code example #39115

Open
@tautvydasversockas

Description

@tautvydasversockas

Type of issue

Code doesn't work

Description

The following code example makes it unclear where the private read-only field _remoteServiceBaseUrl is set from. It is not injected via the constructor nor has a constant value set or a way to be set from another class.

public class CatalogService : ICatalogService
{
    private readonly HttpClient _httpClient;
    private readonly string _remoteServiceBaseUrl;

    public CatalogService(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    public async Task<Catalog> GetCatalogItems(int page, int take,
                                               int? brand, int? type)
    {
        var uri = API.Catalog.GetAllCatalogItems(_remoteServiceBaseUrl,
                                                 page, take, brand, type);

        var responseString = await _httpClient.GetStringAsync(uri);

        var catalog = JsonConvert.DeserializeObject<Catalog>(responseString);
        return catalog;
    }
}

Page URL

https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests

Content source URL

https://github.com/dotnet/docs/blob/main/docs/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests.md

Document Version Independent Id

[email protected]

Article author

@jamesmontemagno

Metadata

  • ID: 7b506236-b211-eb9d-b571-5efecdde76c8
  • Service: dotnet-architecture
  • Sub-service: microservices

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions