-
Type: Task
-
Resolution: Gone away
-
Priority: 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"); } }