Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3868

Using internal constructor of any ValueObject par of an aggregate is not possible ?

    • Type: Icon: Task Task
    • Resolution: Gone away
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: BSON

      Hi,

      I would like to work with Domain Driven Design Tactical patterns, using MongoDb as the storage engine of my aggregates.

      To ensure object encapsulation I need to provide internal scoped constructor (for internal object creation in my Domain layer), and public factories for extra domain layer object creation.

       

      Example :

      Aggregate 

          public class FlashInfo : AggregateRoot<FlashInfoId>
          {
              public Information Text { get; private set; }
              public DateTime ActivationDate { get; private set; }
              public DateTime? LastModified { get; private set; }
              public User CreatedBy { get; private set; }
              public User ModifiedBy { get; private set; }
          
           // ...
      
          }

      Value Object 

          public class Information : Value<Information>
          {
             public string Text { get; } // Satisfy the serialization requirements 
             internal Information(string text)
              {
                  Text = text;
              }        
      
              public static implicit operator string(Information info) => info.Text;
                  
              public static Information CreateInformation(string text)
              {
                  CheckValidity(text);
                  return new Information(text);
              }
      
              private static void CheckValidity(string text)
              {
                  if (string.IsNullOrEmpty(text))
                      throw new InformationTextIsEmptyException("The information text must not be null or empty");            
      
      if (text.Length > 100)
                      throw new ArgumentOutOfRangeException(nameof(text), "The information text cannot be longer that 100 characters");
              }
          }
      

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            nicolasrey@laposte.net Nicolas REY
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: