【问题标题】:Use custom conventions when persisting Rebus sagas in MongoDb在 MongoDb 中持久化 Rebus saga 时使用自定义约定
【发布时间】:2014-04-21 13:43:16
【问题描述】:

当我将我的域存储在 MongoDB 中时,我使用自定义约定(如 here 中所述)以便将我的枚举作为字符串表示形式进行持久化,因为我们在调试时发现它更容易。

在 Rebus 中使用 MongoDB 作为我的 saga 存储时,我也想这样做。有没有办法做到这一点?

【问题讨论】:

    标签: c# mongodb rebus


    【解决方案1】:

    好吧,我的错……约定是使用 ConventionsRegistry 全局定义的

    var conventions = new ConventionPack();
    conventions.Add(new EnumSerializationConvention(BsonType.String));
    ConventionRegistry.Register("Saga conventions", conventions, x => true);
    

    关键是 Register 方法的第三个参数,它充当过滤器来选择受约定影响的类(在我的例子中,我是按命名空间过滤的,这就是不使用 saga 数据的原因beign 正确持久化)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 2014-10-19
      • 2016-04-06
      相关资源
      最近更新 更多