文章管理包含會員端(我的文章、發布文章)與管理端(審核、列表、編輯、刪除)。核心實體關係:



namespace Ninesky.IDAL
{
public interface ICommonModelRepository : IBaseRepository { }
public interface ICategoryRepository : IBaseRepository { }
public interface IArticleRepository : IBaseRepository { }
public interface IAttachmentRepository : IBaseRepository { }
}
namespace Ninesky.DAL
{
public class CommonModelRepository : BaseRepository, ICommonModelRepository { }
public class CategoryRepository : BaseRepository, ICategoryRepository { }
public class ArticleRepository : BaseRepository, IArticleRepository { }
public class AttachmentRepository : BaseRepository, IAttachmentRepository { }
}
namespace Ninesky.IBLL
{
public interface ICategoryService : IBaseService { }
public interface IArticleService : IBaseService { }
public interface IAttachmentService : IBaseService { }
public interface ICommonModelService : IBaseService
{
// 共用分頁查詢,供 Article/Consultation 等複用
IQueryable FindPageList(out int total, int pageIndex, int pageSize,
string model, string title, int categoryId, string inputer,
DateTime? fromDate, DateTime? toDate, int orderCode);
}
}
namespace Ninesky.BLL
{
public class CategoryService : BaseService, ICategoryService
{
public CategoryService() : base(RepositoryFactory.CategoryRepository) { }
}
public class ArticleService : BaseService, IArticleService
{
public ArticleService() : base(RepositoryFactory.ArticleRepository) { }
}
public class AttachmentService : BaseService, IAttachmentService
{
public AttachmentService() : base(RepositoryFactory.AttachmentRepository) { }
}
public class CommonModelService : BaseService, ICommonModelService
{
public CommonModelService() : base(RepositoryFactory.CommonModelRepository) { }
// 實作 FindPageList...
}
}
namespace Ninesky.Web.Areas.Member.Controllers
{
[Authorize]
public class CategoryController : Controller
{
private readonly ICategoryService _service = new CategoryService();
}
public class ArticleController : Controller
{
private readonly IArticleService _articleService = new ArticleService();
private readonly ICommonModelService _commonModelService = new CommonModelService();
}
[Authorize]
public class AttachmentController : Controller
{
private readonly IAttachmentService _attachmentService = new AttachmentService();
}
}
| 設計決策 | 優勢 |
|---|---|
| CommonModel 統一入口 | Article、Attachment、Comment 皆掛載於 CommonModel,Service 層針對 CommonModel 操作,避免重複建立 DAL/BLL |
| 模型擴展模式 | Article 為獨立實體,透過 CommonModel.Article 導覽屬性關聯,符合開放封閉原則 |
| Repository Factory | BLL 建構子注入 Repository,降低耦合,利於單元測試 |
| Area 隔離 | Member 區域獨立控制器,配合 [Authorize] 統一權限控管 |
| 共用查詢介面 | ICommonModelService.FindPageList 服務於所有內容模型 |
本篇確立文章管理的領域模型與分層架構。關鍵創新在於 CommonModel 作為內容管理的「統一抽象」,透過導覽屬性擴展不同業務實體,配合共用的 ICommonModelService 實現查詢邏輯複用。這種設計讓新增內容類型(如產品、公告、招聘)只需建立擴展實體並掛載至 CommonModel,無需修改基礎架構,極大提升系統擴展性。