You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
using AutoMapper;
|
|
using Kean.Domain.Stock.Commands;
|
|
using Kean.Domain.Stock.Models;
|
|
using Kean.Domain.Stock.Repositories;
|
|
using Kean.Domain.Stock.SharedServices.Proxies;
|
|
using Kean.Infrastructure.Configuration;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Domain.Stock.CommandHandlers
|
|
{
|
|
/// <summary>
|
|
/// 记录命令处理程序
|
|
/// </summary>
|
|
public sealed class RecordCommandHandler : CommandHandler<RecordCommand>
|
|
{
|
|
private readonly ICommandBus _commandBus; // 命令总线
|
|
private readonly IMapper _mapper; // 模型映射
|
|
private readonly IRecordRepository _recordRepository;
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public RecordCommandHandler(
|
|
ICommandBus commandBus,
|
|
IMapper mapper,
|
|
IRecordRepository recordRepository)
|
|
{
|
|
_commandBus = commandBus;
|
|
_mapper = mapper;
|
|
_recordRepository = recordRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
public override async Task Handle(RecordCommand command, CancellationToken cancellationToken)
|
|
{
|
|
var record = _mapper.Map<Record>(command);
|
|
await _recordRepository.Append(record);
|
|
}
|
|
}
|
|
}
|
|
|