question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RestEase.HttpClientFactory .NET5 does not seem to register my typed client.

See original GitHub issue

Error

❯ dotnet run
Building...
Unhandled exception. System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: RestEaseWorker.Worker': Unable to resolve service for type 'RestEaseWorker.IPersonAPI' while attempting to activate 'RestEaseWorker.Worker'.)
 ---> System.InvalidOperationException: Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: RestEaseWorker.Worker': Unable to resolve service for type 'RestEaseWorker.IPersonAPI' while attempting to activate 'RestEaseWorker.Worker'.        
 ---> System.InvalidOperationException: Unable to resolve service for type 'RestEaseWorker.IPersonAPI' while attempting to activate 'RestEaseWorker.Worker'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceDescriptor serviceDescriptor, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngine engine, ServiceProviderOptions options) 
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngine engine, ServiceProviderOptions options) 
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder)
   at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter`1.CreateServiceProvider(Object containerBuilder)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at RestEaseWorker.Program.Main(String[] args) in C:\Users\Desktop\RestEaseWorker\Program.cs:line 15

I am sure I am missing something silly, but I followed the directions here: https://github.com/canton7/RestEase#using-httpclientfactory

Repro: https://github.com/VictorioBerra/restease-httpclientfactory-issue

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
canton7commented, Dec 17, 2020

Should be fixed in 1.5.2

1reaction
canton7commented, Dec 17, 2020

Ah, misread the title, my bad

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - HttpClientFactory and typed-client?
1 Answer. In Typed-Client, Dotnet uses HttpClientFactory to create the instance of HttpClient , using that instance they will create your ...
Read more >
canton7/RestEase: Easy-to-use typesafe REST API client ...
Easy-to-use typesafe REST API client library for .NET Standard 1.1 and .NET Framework 4.5 and higher, which is simple and customisable.
Read more >
Creating and Using HTTP Client SDKs in .NET 6 - InfoQ
In this article, the author explains the process behind developing HTTP Client SDKs in .NET 6. The article also contains a sample SDK ......
Read more >
Make HTTP requests using IHttpClientFactory in ASP.NET ...
The typed client is registered as transient with DI. In the preceding code, AddHttpClient registers GitHubService as a transient service.
Read more >
IHttpClientFactory Patterns: Using Typed Clients from ...
When defining typed clients in your ConfigureServices method, the typed service is registered with transient scope. This means that a new ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found