我參加了Jimmy的MediatR DI 1.0.1課程。我試圖將基於該課程示例的項目升級到2.0.0,但我找不到任何升級步驟。MediatR依賴注入的升級步驟
下面是該課程的一個具體示例。我已經將IAsyncRequest更改爲IRequest,並且看起來是正確的。剩下的錯誤是:
public class EmployeeEditHandler : AsyncRequestHandler<EmployeeEditModel>
和
protected override async Task HandleCore(EmployeeEditModel message)
我應該AsyncRequestHandler改爲? HandleCore是否需要更改?
namespace EmployeeDirectory.ViewModels
{
using MediatR;
//Other using statements removed for this example
public class EmployeeEditQuery : IAsyncRequest<EmployeeEditModel>
{
public Guid Id { get; set; }
}
public class EmployeeEditModel : IAsyncRequest
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public class EmployeeEditQueryHandler
: IAsyncRequestHandler<EmployeeEditQuery, EmployeeEditModel>
{
private readonly DirectoryContext _dbContext;
public EmployeeEditQueryHandler(DirectoryContext dbContext)
{
_dbContext = dbContext;
}
public async Task<EmployeeEditModel> Handle(EmployeeEditQuery message)
{
var model = await _dbContext
.Employees
.Where(e => e.Id == message.Id)
.ProjectTo<EmployeeEditModel>()
.SingleOrDefaultAsync();
return model;
}
}
public class EmployeeEditHandler : AsyncRequestHandler<EmployeeEditModel>
{
private readonly DirectoryContext _dbContext;
public EmployeeEditHandler(DirectoryContext dbContext)
{
_dbContext = dbContext;
}
protected override async Task HandleCore(EmployeeEditModel message)
{
var employee = await _dbContext.Employees
.SingleOrDefaultAsync(e => e.Id == message.Id);
Mapper.Map(message, employee);
}
}
}