我已经创建了一个接口,其中实现应该处理命令和查询:
public interface IProcessor : IDisposable
{
void Process<TCommand>(TCommand command) where TCommand : ICommand;
TOutput Return<TQuery, TOutput>(TQuery query) where TQuery : IQuery;
}
这里的问题是我想让IProcessor接口方法在使用时尽可能短。
public class WhateverController : ApiController
{
private readonly IProcessor _processor;
public WhateverController(IProcessor processor)
{
_processor = processor;
}
public List<Guid> Post(List<Whatever> whatevers)
{
var command = new CreateWhatever{ Whatevers = whatevers};
_processor.Process(command);
return command.Result;
}
public List<Whatever> Get()
{
var query = new GetAllWhatevers { };
return _processor.Return(query);
}
protected override void Dispose(bool disposing)
{
_processor.Dispose();
base.Dispose(disposing);
}
}
我想让IProcessor.Return(查询)可以使用而不是IProcessor.Return所以更短的版本... 我已经尝试过创建一个IQuery&lt; TOutput&gt;但我总是有一个错误,应该有更多的类型约束...