在領域層中,可以實現實體與聚合根的業務邏輯,在實現業務邏輯之前,我們首先要確定實體和聚合根的一些基本行為,比如判斷實體是否相等。關於領域對象的具體業務邏輯實現,因為涉及到要與數據庫交互,所以等看完倉儲的實現后,再實現領域對象的業務邏輯。
using System; using Order.Domain.Aggreate; namespace Order.Domain.Model { public abstract class Entity : IEntity { private Guid id = Guid.NewGuid(); public Guid Id { get { return id; } } public override bool Equals(object obj) { if (obj == null) return false; if (ReferenceEquals(this, obj)) return true; return this.Id == (obj as IEntity).Id; } public override int GetHashCode() { return this.Id.GetHashCode(); } } }
namespace Order.Domain.Model { public abstract class AggreateRoot:Entity { } }
歡迎加入QQ討論群:309287205