相关疑难解决方法(0)

Autofac解决CQRS CommandDispatcher中的依赖关系

我正在尝试实现一个简单的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)

.net c# dependency-injection autofac cqrs

12
推荐指数
1
解决办法
3094
查看次数

标签 统计

.net ×1

autofac ×1

c# ×1

cqrs ×1

dependency-injection ×1