【发布时间】:2020-02-24 07:22:42
【问题描述】:
我读到一篇关于 DDD 的文章,说 Aggregate 应该负责创建或更新 Aggregate Root Child。我唯一关心的是,如果子聚合有很多属性怎么办。
我通常做的就是这样
public class Parent
{
public Child Child1{ get; protected set; }
public void SetOrUpdateChild(string prop1, string prop2, string prop3, string prop4, string prop5, string prop6, string prop7, string prop8, string prop9, string prop10)
{
Child1 = Child.Create(prop1, prop2, prop3, prop4, prop5, prop6, prop7, prop8, prop9, prop10);
}
}
public class Child
{
public Child(string prop1, string prop2, string prop3, string prop4, string prop5, string prop6, string prop7, string prop8, string prop9, string prop10)
{
Prop1 = prop1;
Prop2 = prop2;
Prop3 = prop3;
Prop4 = prop4;
Prop5 = prop5;
Prop6 = prop6;
Prop7 = prop7;
Prop8 = prop8;
Prop9 = prop9;
Prop10 = prop10;
}
public string Prop1 { get; protected set; }
public string Prop2 { get; protected set; }
public string Prop3 { get; protected set; }
public string Prop4 { get; protected set; }
public string Prop5 { get; protected set; }
public string Prop6 { get; protected set; }
public string Prop7 { get; protected set; }
public string Prop8 { get; protected set; }
public string Prop9 { get; protected set; }
public string Prop10 { get; protected set; }
public static Child Create(string prop1, string prop2, string prop3, string prop4, string prop5, string prop6, string prop7, string prop8, string prop9, string prop10)
{
return new Child(prop1, prop2, prop3, prop4, prop5, prop6, prop7, prop8, prop9, prop10);
}
}
有没有更好的方法来做到这一点?我知道我可以将 Child 对象传递给 AddChild 方法,但我认为这不是理想的方法。我担心的是,如果 Child 对象增长,将很难管理。
【问题讨论】:
-
然后使用构造对象,但这确实不适合stackoverflow
标签: c# .net domain-driven-design