領域驅動設計案例之領域層實體與聚合根實現


在領域層中,可以實現實體與聚合根的業務邏輯,在實現業務邏輯之前,我們首先要確定實體和聚合根的一些基本行為,比如判斷實體是否相等。關於領域對象的具體業務邏輯實現,因為涉及到要與數據庫交互,所以等看完倉儲的實現后,再實現領域對象的業務邏輯。

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM