我正在尝试实现一个简单的CQRS应用程序示例.
这是我的"命令"部分的结构:
public interface ICommand
{
}
//base interface for command handlers
interface ICommandHandler<in TCommand> where TCommand: ICommand
{
void Execute(TCommand command);
}
// example of the command
public class SimpleCommand: ICommand
{
//some properties
}
// example of the SimpleCommand command handler
public class SimpleCommandHandler: ICommandHandler<SimpleCommand>
{
public void Execute(SimpleCommand command)
{
//some logic
}
}
Run Code Online (Sandbox Code Playgroud)
这是界面ICommandDipatcher.它将命令分派给其处理程序.
public interface ICommandDispatcher
{
void Dispatch<TCommand>(TCommand command) where TCommand : ICommand;
}
Run Code Online (Sandbox Code Playgroud)
这是默认实现,ICommandDispatcher主要问题是通过命令的类型获取必要的命令处理程序Autofac.
public class DefaultCommandDispatcher …Run Code Online (Sandbox Code Playgroud)