客户端程序通过命令告知系统“应该做什么”。事实上,这是一种单向的交互过程,客户端程序仅仅向领域模型发送命令请求,它们并不会通过领域模型来查询某些数据信息。在CQRS架构的应用程序中,“查询”是另一部分的内容,这将在接下来的章节中单独讨论。当应用服务器端接收到来自客户端的命令请求后,就会将这些命令推送到命令总线。命令处理器会侦听命令总线,并相应地处理命令请求。现在,让我们在TinyLibraryCQRS解决方案中创建命令与命令解释器。

  1. 右键单击TinyLibraryCQRS解决方案,单击 Add | New Project… 菜单,这将打开Add New Project对话框
  2. Installed Templates选项卡下,选择Visual C# | Windows,然后选择Class Library,确保所选的.NET版本是.NET Framework 4,然后在Name文本框中,输入TinyLibrary.Commands,并单击OK按钮
  3. TinyLibrary.Commands项目上,右键单击References节点,单击Add Reference…菜单,这将打开Add Reference对话框
  4. .NET选项卡下,选择Apworks,然后单击OK按钮
  5. 添加下面的代码:
    using System;
    using Apworks.Commands;
       3:  
    namespace TinyLibrary.Commands
       5: {
       6:     [Serializable]
    class BorrowBookCommand : Command
       8:     {
    long ReaderId { get; set; }
    long BookId { get; set; }
      11:  
    long bookId)
      13:         {
    this.ReaderId = readerId;
    this.BookId = bookId;
      16:         }
      17:     }
      18:  
      19:     [Serializable]
    class CreateBookCommand : Command
      21:     {
    private set; }
    private set; }
    private set; }
    private set; }
    private set; }
    private set; }
      28:  
    string title, 
    string publisher, 
      31:             DateTime pubDate, 
    bool lent)
      33:         {
    this.Title = title;
    this.PubDate = pubDate;
    this.Publisher = publisher;
    this.ISBN = isbn;
    this.Pages = pages;
    this.Lent = lent;
      40:         }
      41:  
    long id, 
    string title, 
    string publisher, 
      45:             DateTime pubDate, 
    bool lent)
    base(id)
      48:         {
    this.Title = title;
    this.PubDate = pubDate;
    this.Publisher = publisher;
    this.ISBN = isbn;
    this.Pages = pages;
    this.Lent = lent;
      55:         }
      56:     }
      57:  
      58:     [Serializable]
    class RegisterReaderCommand : Command
      60:     {
    private set; }
    private set; }
      63:  
    string name)
      65:         {
    this.LoginName = loginName;
    this.Name = name;
      68:         }
      69:  
    base(id)
      71:         {
    this.LoginName = loginName;
    this.Name = name;
      74:         }
      75:     }
      76:  
      77:     [Serializable]
    class ReturnBookCommand : Command
      79:     {
    long ReaderId { get; set; }
    long BookId { get; set; }
      82:  
    long bookId)
      84:         {
    this.ReaderId = readerId;
    this.BookId = bookId;
      87:         }
      88:     }
      89: }

相关文章:

  • 2022-01-14
  • 2021-10-29
  • 2021-08-25
  • 2022-02-10
  • 2021-09-28
  • 2021-09-06
  • 2021-06-19
  • 2021-05-30
猜你喜欢
  • 2021-11-08
  • 2021-12-07
  • 2021-10-16
  • 2022-03-02
  • 2022-02-27
  • 2021-09-05
  • 2021-11-05
相关资源
相似解决方案