zoukankan      html  css  js  c++  java
  • eventFlow 系列 <三> 查询所有

    接着上面的例子,产生2条数据。怎么把这两条数据查询出来呢?

    var commandBus = resolver.Resolve<ICommandBus>();
                    var cm = new ExampleCommand(exampleId, 42, 88);
                    var executionResult = await commandBus.PublishAsync(cm,CancellationToken.None).ConfigureAwait(false);var exampleId2 = ExampleId.New;
                    var cm3 = new ExampleCommand(exampleId2, 423, 888);
                    var executionResult3 = await commandBus.PublishAsync(cm3, CancellationToken.None).ConfigureAwait(false);

    这要添加下面这2个类。查询需要在加粗的地方修改逻辑。

    public class ExampleQuery : IQuery<IReadOnlyCollection<ExampleReadModel>>
        {
        }
    
      public class ExampleQueryHandler : IQueryHandler<ExampleQuery, IReadOnlyCollection<ExampleReadModel>>
        {
            private readonly IInMemoryReadStore<ExampleReadModel> _readStore;
    
            public ExampleQueryHandler( IInMemoryReadStore<ExampleReadModel> readStore)
            {
                _readStore = readStore;
            }
    
            public async Task<IReadOnlyCollection<ExampleReadModel>> ExecuteQueryAsync(ExampleQuery query, CancellationToken cancellationToken)
            {
            return await _readStore.FindAsync( rm => true, cancellationToken) .ConfigureAwait(false);
           } 
    }

    上端调用的代码:

     var exampleReadModels = await queryProcessor.ProcessAsync(new ExampleQuery(), CancellationToken.None).ConfigureAwait(false);
    气功波(18037675651)
  • 相关阅读:
    2016/05/16 thinkphp3.2.2 验证码使用
    2016/05/16 UEditor 文本编辑器 使用教程与使用方法
    2016/05/15 ThinkPHP3.2.2 表单自动验证实例 验证规则的数组 直接写在相应的控制器里
    DropzoneJS 使用指南
    MVC设计模式
    Smarty 配置文件的读取
    会话控制
    JS中的call和apply
    CSS选择器
    XML
  • 原文地址:https://www.cnblogs.com/qgbo/p/11582946.html
Copyright © 2011-2022 走看看