货币是不是价值对象

kam*_*mal 0 c# oop domain-driven-design value-objects

我有 Person 聚合,这是根聚合

public class Person 
{
    private int id;
    private readonly PersonID personID;

    private readonly string email;
    private readonly string firstName;
    private readonly string lastName;

    private readonly string username;
    private readonly string password;
    private readonly Address BillingAddress;
}

public class Currency : IValueObject<Currency>
{
    private string name;
    private string currencyCode;
    private decimal rate;
    private string displayLocale;
    private string customFormatting;
    private int displayOrder;
    private bool primaryExchangeRateCurrency;
    private bool primaryStoreCurrency;

    //<summary>
    //Gets or a value indicating whether the currency is primary exchange rate currency
    //</summary>

    public bool IsPrimaryExchangeRateCurrency
    {
       get
       {
           return primaryExchangeRateCurrency;
       }
    }

   /// <summary>
    /// Gets or a value indicating whether the currency is primary store currency
    /// </summary>

    public bool IsPrimaryStoreCurrency
    {
         get
         {
                return primaryStoreCurrency;
         }
    }
}
Run Code Online (Sandbox Code Playgroud)

和 Currency 类,该类将在 Person 类中引用。

所以现在如果创建了一个 Person 实体,我们也需要将它关联一个货币。但是在创建的所有货币中,我想知道哪个是默认的主要商店货币。我不想通过 Person 知道它,因为它只包含单一货币。我想从所有创建的人的货币中获得一种货币,它是 PrimaryStoreCurrency。

我想在下拉列表中绑定货币,以便用户可以从下拉列表中选择其货币并在我们的系统中注册。

那么,我是否将货币创建为单独的聚合?

M.S*_*eer 5

如果您所说的货币是应用程序中的货币定义,如 USD、EGP、EUR、.. 等,则它应该是可重用的实体。如果您指的是货币金额的价值,例如 1000 美元,则它是一个封装金额和货币类型的价值对象。