【问题标题】:Pricing plan specification according to DDD根据 DDD 的定价计划规范
【发布时间】:2017-11-08 23:44:37
【问题描述】:

我正在尝试根据定价计划规范对 Web API 实施限制。

例子:

用户订阅了三个计划之一。每个计划都允许为单个用户连接多个社交媒体配置文件。当前,当用户请求连接新配置文件时,Web api 处理程序中会实施限制。

随着需要满足更多规范,它增加了 api 处理程序的复杂性,并且它要求抽象。我正在阅读一本关于领域驱动设计的书,并遇到了 SPECIFICATION 模式。

问题是应该在哪里应用规范模式。在应用层(api 处理程序在哪里)还是在域层?

如果它属于领域层,我应该在添加新配置文件时在 Repository 中强制规范吗?

    socialMediaProfileRepository.add(socialMediaProfile, specification);

【问题讨论】:

    标签: domain-driven-design


    【解决方案1】:

    该规则最有可能在聚合根中执行,例如UserAccount。如果UserAccount 跟踪它链接到MediaProfile 并且有一个定义MediaProfileLinkageSpecificationPricingPlan,它可能看起来像:

    void linkMediaProfile(userAccountId, mediaProfileData) {
        userAccount = userAccountRepository.findById(userAccountId);
        mediaProfile = new MediaProfile(mediaProfileData);
    
        //throws if the related user profile linkage spec is not satisfied
        userAccount.linkMediaProfile(mediaProfile);
        userAccountRepository.save(userAccount);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多