大家好。我正在重写项目的架构,当我完成时,我收到了这个错误:
"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'.)"
这是斯图普:
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<TRepository<OrderModel>, OrderRepository>();
services.AddTransient<IOrderService, 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";
}

public OrderRepository(Box box)- 构造函数要求一些Box。但是你没有在容器中注册这个类。因此,容器不知道究竟应该将什么滑入构造函数并给出异常。