Commit 93236c4c by dingsongjie

简化 command

parent 76b0558a
using Pole.Application.Command;
using Pole.Application.Cqrs;
using Pole.Grpc.ExtraType;
using PoleSample.Apis.Product;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Product.Api.Application.Command
{
public class AddProductTypeCommand: ICommand<CommonCommandResponse>
{
public AddProductTypeRequest Request { get; set; }
}
}
...@@ -12,9 +12,9 @@ using System.Linq; ...@@ -12,9 +12,9 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Product.Api.Application.Command.CommandHandler namespace Product.Api.Application.CommandHandler
{ {
public class AddProductTypeCommandHandler : ICommandHandler<AddProductTypeCommand, CommonCommandResponse> public class AddProductTypeCommandHandler : ICommandHandler<Command<AddProductTypeRequest, CommonCommandResponse>, CommonCommandResponse>
{ {
private readonly IProductTypeRepository _productTypeRepository; private readonly IProductTypeRepository _productTypeRepository;
private readonly IUnitOfWorkManager _unitOfWorkManager; private readonly IUnitOfWorkManager _unitOfWorkManager;
...@@ -23,9 +23,9 @@ namespace Product.Api.Application.Command.CommandHandler ...@@ -23,9 +23,9 @@ namespace Product.Api.Application.Command.CommandHandler
_productTypeRepository = productTypeRepository; _productTypeRepository = productTypeRepository;
_unitOfWorkManager = unitOfWorkManager; _unitOfWorkManager = unitOfWorkManager;
} }
public async Task<CommonCommandResponse> Handle(AddProductTypeCommand request, CancellationToken cancellationToken) public async Task<CommonCommandResponse> Handle(Command<AddProductTypeRequest, CommonCommandResponse> request, CancellationToken cancellationToken)
{ {
var productType = new Domain.ProductTypeAggregate.ProductType(request.Request.Id, request.Request.Name); var productType = new Domain.ProductTypeAggregate.ProductType(request.Data.Id, request.Data.Name);
_productTypeRepository.Add(productType); _productTypeRepository.Add(productType);
......
...@@ -4,7 +4,6 @@ using Pole.Application.Command; ...@@ -4,7 +4,6 @@ using Pole.Application.Command;
using Pole.Application.Cqrs; using Pole.Application.Cqrs;
using Pole.Grpc.ExtraType; using Pole.Grpc.ExtraType;
using PoleSample.Apis.Product; using PoleSample.Apis.Product;
using Product.Api.Application.Command;
using Product.Api.Infrastructure; using Product.Api.Infrastructure;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -22,7 +21,7 @@ namespace Product.Api.Grpc ...@@ -22,7 +21,7 @@ namespace Product.Api.Grpc
} }
public override Task<CommonCommandResponse> Add(AddProductTypeRequest request, ServerCallContext context) public override Task<CommonCommandResponse> Add(AddProductTypeRequest request, ServerCallContext context)
{ {
var cpmmand = new AddProductTypeCommand { Request = request }; var cpmmand = new Command<AddProductTypeRequest, CommonCommandResponse>(request);
return _commandBus.Send(cpmmand); return _commandBus.Send(cpmmand);
} }
} }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Pole.Application.Command
{
public class Command<TRequest,TResponse>:ICommand<TResponse>
{
public Command(TRequest request)
{
Data = request;
}
public TRequest Data { get; private set; }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment