我正在一个内容开发场景中工作,其中实体很可能在不完整状态下创建并在一段时间内保持不完整。所涉及的工作流程非常临时,使我无法使用更结构化的 DDD 方法。
我有一组必须始终满足的验证规则,以及在实体“完成”之前必须满足的另一组验证规则。
我已经在使用内置的 ASP.NET MVC 验证来验证前者。我可以用什么方法来捕捉后者?
例如:-
public class Foo
{
public int Id { get; set; }
public virtual ICollection<Bar> Bars { get; set; }
}
public class Bar
{
public int Id { get; set; }
[Required] // A Bar must be owned by a Foo at all times
public int FooId { get; set; }
public virtual Foo Foo { get; set; }
[Required] // A Bar must have a working title at all times
public string WorkingTitle { get; set; }
public bool IsComplete { get; set; }
// Cannot use RequiredAttribute on Description as the
// entity is very likely to be created without one,
// however a Description is required before the entity
// can be marked as "IsComplete"
public string Description { get; set; }
}