Unable to resolve service for type while attempting to activate

For the Dependency Injection framework to resolve IRepository, it must first be registered with the container. For example, in ConfigureServices, add the following:

services.AddScoped<IRepository, MemoryRepository>();

AddScoped is just one example of a service lifetime:

For web applications, a scoped lifetime indicates that services are created once per client request (connection).

See the docs for more information on Dependency Injection in ASP.NET Core.

Leave a Comment