N
N
Nik Faraday2021-11-15 18:04:59
ASP.NET
Nik Faraday, 2021-11-15 18:04:59

How to fix System.AggregateException: "Some services are not able to be constructed"?

Hello

Problem in brief:
I use GenericRepository for access to a DB. Also in the project there are various services that require a GenericRepository object in the constructor to work.

In the error output, it says that the error generally occurred in DependencyInjection.dll

Knocks out immediately at startup in general in Main'a There is

no error if you remove GenericRepository from the service constructor

Maybe I registered it incorrectly in Startup.css (Code below) ?

services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>));


Upd: full description of the error
61927788e7787450669925.png
619277a424fc8269142826.png

Upd2: I checked the method of excluding all methods from the GenericRepository and the services that use it and found that the problem has nothing to do with the methods and the error occurs only when I try to pass the GenericRepository object to the service constructor
Again, the question with what it can be connected?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nik Faraday, 2022-03-10
@NikFaraday

Solution: The problem can occur if another class where you are trying to get an object via DI uses a class instead of an interface.
Also, an error can occur if the service class is simply not registered in the pipeline

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question