Что произошло:
- Вчера мой проект работал правильно, без ошибок.
- Сегодня я по ошибке обновил некоторые пакеты NuGet.
- После этого я попробовал MediatR 10.0.0 → слишком много критических изменений.
- Затем я попробовал MediatR 8.0.1 → тоже несовместим.
- Какую бы версию я ни установил, я получаю ошибки интерфейса или метода расширения.
Program.cs:
Код: Выделить всё
using udemycarbook.Application.Features.CQRS.Handlers.AboutHandlers;
using udemycarbook.Persistence.Context;
using udemycarbook.Application.Interfaces;
using udemycarbook.Persistence.Repositories;
using udemycarbook.Application.Features.CQRS.Handlers.BannerHandlers;
using udemycarbook.Application.Features.CQRS.Handlers.BrandHandlers;
using udemycarbook.Application.Features.CQRS.Handlers.CarHandlers;
using udemycarbook.Application.Interfaces.CarInterfaces;
using udemycarbook.Persistence.Repositories.CarRepository;
using udemycarbook.Application.Features.CQRS.Handlers.CategoryHandlers;
using udemycarbook.Application.Features.CQRS.Handlers.ContactHandlers;
using udemycarbook.Application.Services;
using UdemyCarBook.Application.Features.CQRS.Handlers.CarHandlers;
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.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddApplicationService(builder.Configuration);
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();
Код: Выделить всё
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace udemycarbook.Application.Features.Mediator.Commands.FeatureCommands
{
public class CreateFeatureCommand : IRequest
{
public string Description { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Name { get; set; }
}
}
Код: Выделить всё
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using udemycarbook.Application.Features.Mediator.Commands.FeatureCommands;
using udemycarbook.Application.Interfaces;
using UdemyCarBookDomain.Entities;
namespace udemycarbook.Application.Features.Mediator.Handlers.FeatureHandlers
{
public class CreateFeatureCommandHandler : IRequestHandler
{
private readonly IRepository _repository;
public CreateFeatureCommandHandler(IRepository repository)
{
_repository = repository;
}
public async Task Handle(CreateFeatureCommand request, CancellationToken cancellationToken)
{
await _repository.CreateAsync(new Feature
{
Name = request.Name
});
}
Task IRequestHandler.Handle(CreateFeatureCommand request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
Я добавляю изображение внутри, но сейчас исправил эти ошибки, добавив это
Код: Выделить всё
Task IRequestHandler.Handle(CreateFeatureCommand request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
'MediatRServiceConfiguration' не содержит определения для 'RegisterServicesFromAssembly', и не может быть найден доступный метод расширения 'RegisterServicesFromAssembly', принимающий первый аргумент типа 'MediatRServiceConfiguration' (вам не хватает директивы using или сборки ссылка?)
и этот
Файл метаданных "'C:\Users\yunus\source\repos\udemycarbook\Core\udemycarbook.Application\obj\Debug\net8.0\ref\udemycarbook.Application.dll' не найден"
Я хочу знать:
- Какая версия MediatR соответствует синтаксису моего кода?
- Как мне правильно зарегистрировать MediatR в Program.cs?
Подробнее здесь: https://stackoverflow.com/questions/798 ... g-problems
Мобильная версия