ОШИБКА:
System.AggregateException
HResult=0x80131500
Сообщение=Некоторые службы не могут быть доступны построен (Ошибка при проверке дескриптора службы «ServiceType: BookACar.Application.Interfaces.CarInterfaces.ICarRepository Lifetime: Scoped ImplementationType: CarRepository»: тип реализации «CarRepository» невозможно преобразовать в тип службы «BookACar.Application.Interfaces.CarInterfaces. ICarRepository') (Ошибка при проверке дескриптора службы 'ServiceType: BookACar.Application.Features.CQRS.Handlers.CarHandlres.GetCarWithBrandQueryHandler Срок службы: Scoped ImplementationType: BookACar.Application.Features.CQRS.Handlers.CarHandlres.GetCarWithBrandQueryHandler': Тип реализации 'CarRepository') 'невозможно преобразовать в тип службы 'BookACar.Application.Interfaces.CarInterfaces.ICarRepository')
Source=Microsoft.Extensions.DependencyInjection
StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceProvider ..ctor(ICollection`1 serviceDescriptors, параметры ServiceProviderOptions)
в Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(службы IServiceCollection, параметры ServiceProviderOptions)
в Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()в Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
в Program.$(String[] args) в C:\Projects\CarBook\Presentation\BookACar.WebApi\Program.cs: строка 51
Это исключение изначально было создано в этом стеке вызовов:
[Внешний код]
Внутреннее исключение 1:
InvalidOperationException: ошибка при проверке дескриптора службы «ServiceType: BookACar.Application.Interfaces.CarInterfaces.ICarRepository Срок службы: Scoped ImplementationType: CarRepository»: тип реализации «CarRepository» невозможно преобразовать в тип службы «BookACar.Application.Interfaces.CarInterfaces». ICarRepository'
Внутреннее исключение 2:
ArgumentException: тип реализации "CarRepository" невозможно преобразовать в тип службы "BookACar.Application.Interfaces.CarInterfaces.ICarRepository"
Интерфейс ICarRepository:
Код: Выделить всё
namespace BookACar.Application.Interfaces.CarInterfaces
{
public interface ICarRepository
{
List GetCarsListWithBrand();
}
}
Класс CarRepository**
Код: Выделить всё
namespace BookACar.Persistence.Repositories.CarRepositories
{
public class CarRepository : ICarRepository
{
private readonly CarBookContext _context;
public CarRepository(CarBookContext context)
{
_context = context;
}
public List GetCarsListWithBrand()
{
var values = _context.Cars.Include(x => x.Brand).ToList();
return values;
}
}
}
Код: Выделить всё
using BookACar.Application.Features.CQRS.Handlers.AboutHandlers;
using BookACar.Application.Features.CQRS.Handlers.BannerHandlres;
using BookACar.Application.Features.CQRS.Handlers.BrandHandlers;
using BookACar.Application.Features.CQRS.Handlers.CarHandlres;
using BookACar.Application.Interfaces;
using BookACar.Application.Interfaces.CarInterfaces;
using BookACar.Persistence.Repositories;
using BookACar.Persistence.Repositories.CarRepositories;
using CarBook.Persistence.CarBookContext;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddScoped();
builder.Services.AddScoped(typeof(IRepository), typeof(Repository));
builder.Services.AddScoped(typeof(ICarRepository), typeof(CarRepository));
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
Подробнее здесь: https://stackoverflow.com/questions/786 ... cted-error