Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

HttpFactory and AddHttpClient in dependency injection #296

Open
yonail opened this issue Oct 1, 2020 · 0 comments
Open

HttpFactory and AddHttpClient in dependency injection #296

yonail opened this issue Oct 1, 2020 · 0 comments

Comments

@yonail
Copy link

yonail commented Oct 1, 2020

Hello!

I'm trying to figure out how I can benefit from the new .netcore HttpFactory dependency injection to register the VSS clients in my startup class like so:

services.AddHttpClient<WorkItemTrackingHttpClient>(client =>
{
    // custom configuration
});

and then in a service/controller method:

public async Task Method([FromServices] WorkItemTrackingHttpClient client, int id)
{
    var workitem = await client.GetWorkItemAsync(id);
    //do something with the workitem...
}

Currently, I'm facing this exception when doing the above:
InvalidOperationException: A suitable constructor for type 'Microsoft.TeamFoundation.WorkItemTracking.WebApi.WorkItemTrackingHttpClient' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

Has any one managed to do it?
Would be good to have a sample for this.

Thanks,
Yoni

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant