AggregateException: Some services are not able to be constructed - c#. Ошибка при инициализации проекта
Всем привет. Я переписывал архитектуру проекта, и как закончил, получаю вот такую ошибку:
"AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Implemantation.IServices.IOrderService Lifetime: Transient ImplementationType: Implemantation.Services.OrderService': Unable to resolve service for type 'DBInfrastructure.TRepository`1[DBInfrastructure.DTOModels.OrderModel]' while attempting to activate 'Implemantation.Services.OrderService'.)"
"InvalidOperationException: Error while validating the service descriptor 'ServiceType: Implemantation.IServices.IOrderService Lifetime: Transient ImplementationType: Implemantation.Services.OrderService': Unable to resolve service for type 'DBInfrastructure.TRepository`1[DBInfrastructure.DTOModels.OrderModel]' while attempting to activate 'Implemantation.Services.OrderService'."
"AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Implemantation.IServices.IOrderService Lifetime: Transient ImplementationType: Implemantation.Services.OrderService': Unable to resolve service for type 'DBInfrastructure.TRepository`1[DBInfrastructure.DTOModels.OrderModel]' while attempting to activate 'Implemantation.Services.OrderService'.)"
Вот Sturtup:
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<TRepository<OrderModel>, OrderRepository>();
services.AddTransient<IOrderService, OrderService>();
}
Вот OrderService:
public class OrderService : IOrderService
{
public readonly Random Randomizer = new();
private readonly TRepository<OrderModel> orderRepository;
public OrderService(TRepository<OrderModel> orderRepository)
{
this.orderRepository = orderRepository;
}
}
Вот TRepository:
public class TRepository<T> : IRepository<T> where T : class
{
public ISchema Schema { get; set; }
public ISpace Space { get; set; }
public IIndex PrimaryIndex { get; set; }
protected Box box { get; set; }
private bool disposedValue;
public TRepository( Box box, string vspace, string viindex)
{
this.box = box;
_ = Init(vspace, viindex);
} // ctor
private async Task Init(string vspace, string viindex)
{
Schema = box.GetSchema();
Space = await box.GetSchema().GetSpace(vspace);
PrimaryIndex = await Space.GetIndex(viindex);
} // init func
}
Вот IRepository:
public interface IRepository<T> : IDisposable where T: class
{
public T FindById<Y>(Y id);
public IEnumerable<T> FindAll();
public Task Create(T model);
public Task Delete(T model);
public Task Update(T moodel);
}
Вот OrderRepository:
public class OrderRepository : TRepository<OrderModel>
{
public OrderRepository(Box box) : base(box, vspace, viindex) { }
private readonly static string vspace = "orders";
private readonly static string viindex = "primary_index";
}
Ошибка возникает при запуске веб приложения.
Вот скриншот ошибки:

Ответы (1 шт):
Автор решения: aepot
→ Ссылка
public OrderRepository(Box box) - конструктор просит какой-то Box. Но вы не зарегистрировали этот класс в контейнере. Следовательно контейнер не знает, что именно надо подсунуть в конструктор и дает исключение.