system.agegrateexception
hresult = 0x80131500
message = некоторые службы не могут быть построены (ошибка, подтверждая дескриптор сервиса. Срок службы: Обзор реализации type: carrepository ': тип реализации' carrepository 'не может быть преобразован в тип службы' bookacar.application.interfaces.carinterfaces.icarrepository ') (Ошибка при проверке дескриптора службы' ServiceType: Bookacar.application.features.cqrs.handlers.carhandlres.getCarWithBrandQueryHandler Lifetime: Scoped repleptiontype: bookacar.application.features.cqrs.handlers.carhandlres.getCarwithBrandQueryHandler ': Тип реализации. 'Bookacar.application.interfaces.carinterfaces.icarrepository')
source=microsoft.extensions.dependencyInction
stacktrace: < /p>
at microsoft.extensions.dependenceInection.ServicePriveDscrection. Параметры ServiceProvideroptions)
at microsoft.extensions.dependencyInction.serviceCollectionContainerBuilderExtensions.BuildServiceProvider (ServiceCollection, ServiceProvideroptions Options) Microsoft.aspnetcore.builder.webapplicationbuilder.build ()
at Program. $ (string [] args) в C: \ Projects \ CarBook \ Presentation \ Bookacar.WebApi \ Program.cs: Line 51 < /p>
Это было первоначально подключено к этому. /> Внутреннее исключение 1:
InvalidoperationException: Ошибка при проверке дескриптора сервиса 'ServiceType: bookacar.application.interfaces.carinterfaces.icarrepository Lifetime: 'Bookacar.application.interfaces.carinterfaces.icarrepository' < /p>
Внутреннее исключение 2:
ArmeryException: тип реализации 'carrepository' не может быть преобразован в тип службы 'bookacar.application.interfaces.carinterfaces.icarrepository' < /p>
ICarRepository Интерфейс:
Код: Выделить всё
namespace BookACar.Application.Interfaces.CarInterfaces
{
public interface ICarRepository
{
List GetCarsListWithBrand();
}
}
< /code>
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;
}
}
}
< /code>
program.cs
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();
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();
< /code>
I tried all ways but I can't fix the problem. Why I am getting this error and how I can fix it?
Подробнее здесь: https://stackoverflow.com/questions/786 ... cted-error