Question: While running the .Net Core 2.0 API endpoint getting below error.

A suitable constructor for type 'RestDataService' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

```
 public partial class RestDataService : IRestDataService
    {
        private static HttpClient _client;
        private static AppConfiguration _configuration;
        private const short MaxRetryAttempts = 3;
        private const short TimeSpanToWait = 2;

        public RestDataService(AppConfiguration configuration)
        {
            _client = configuration.HttpClient;
            _configuration = configuration;
        }
........

```

And my startup class is something like this :

```
  // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            var config = new AppConfiguration
            {
                Environment = Configuration["environment"],
            };

            services.AddMvc().AddJsonOptions(o => o.SerializerSettings.NullValueHandling = NullValueHandling.Include);
            services.AddMemoryCache();
            services.AddCors();
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
                services.AddSingleton(Configuration);
                services.AddSingleton(config);
            services.AddLogging();
            services.AddTransient<IRestDataService, RestDataService>();

services.AddHttpClient<IRestDataService, RestDataService>()
                .AddPolicyHandler(request => request.Method == HttpMethod.Get ? retryPolicy : noOp);

```

Any suggestions, to get rid of this? constructor is already public and all the parameters are registered in startup file

Answer: 
I received the error *"A suitable constructor for type '<type>' could not be located."* after accidentally generating a **protected** constructor instead of **public** constructor. Marking it back to *public* fixed it.
I just ran across this issue because I was accidentally registering `HttpClient` to an `interface`.

```cs
public void ConfigureServices(IServiceCollection services) {
  // !! Wrong, this is done automatically by AddHttpClient<IMyService, MyService>()
  services.AddTransient<IMyService, MyService>();

  // !! There is no suitable constructor for IMyService, since it is an interface.
  services.AddHttpClient<IMyService>();

  // Instead, let AddHttpClient manage your service's lifetime, 
  // and tell it the implementation.
  // It is registered with a Transient lifetime as described below.
  services.AddHttpClient<IMyService, MyService>();
}

```

Important context, from source: <https://www.stevejgordon.co.uk/ihttpclientfactory-patterns-using-typed-clients-from-singleton-services>

> 
> When defining typed clients in your ConfigureServices method, the typed service is registered with transient scope. This means that a new instance is created by the DI container every time one is needed. The reason this occurs is that a HttpClient instance is injected into the typed client instance. That HttpClient instance is intended to be short lived so that the HttpClientFactory can ensure that the underlying handlers (and connections) are released and recycled.
> 
> 
>