Tag: 域驱动设计的

使用DDD创建子实体的正确方法

我是DDD世界的新手,在阅读了几本关于它的书之后(其中包括Evans DDD)我无法在互联网上找到我的问题的答案:用DDD创建子实体的正确方法是什么? 你看,互联网上的很多信息都在一些简单的层面上运作。 但是细节上的恶魔并没有为了简单起见而在数十个DDD样本中省略它们。 我在stackoverflow上来自我在similair问题上的回答 。 我对这个问题的看法并不完全满意,所以我认为我需要详细说明这个问题。 例如,我需要创建代表汽车命名的简单模型:公司,模型和修改(例如,日产天籁2012 – 将是“日产”公司,“天籁”模型和“2012”修改)。 我想要创建的模型的草图如下所示: CarsCompany { Name (child entities) Models } CarsModel { (parent entity) Company Name (child entities) Modifications } CarsModification { (parent entity) Model Name } 所以,现在我需要创建代码。 我将使用C#作为语言,将NHibernate用作ORM。 这很重要,通常在互联网上的大量DDD样本中没有显示。 第一种方法。 我将从通过工厂方法创建典型对象的简单方法开始。 public class CarsCompany { public virtual string Name { get; protected set; } public virtual […]

将异步模型集映射到异步ViewModel集合

我正在使用一个项目,我需要使用Async编程C#。 我在Model和ViewModel之间使用Automapper进行映射。 对于异步数据,我创建了一个map方法,如下所示: public static async Task<IEnumerable> ModelToViewModelCollectionAsync(this Task<IEnumerable> persons) { return await Mapper.Map<Task<IEnumerable>, Task<IEnumerable>>(persons); } 我将此映射方法称为如下(在我的服务类中): public async Task<IEnumerable> GetAllAsync() { return await _personRepository.GetAllAsync(“DisplayAll”).ModelToViewModelCollectionAsync(); } 最后我在控制器内调用了我的服务类。 public async Task Index() { return View(await PersonFacade.GetAllAsync()); } 但是当我运行我的项目时,它会向我显示以下exception Missing type map configuration or unsupported mapping. Mapping types: Task`1 -> Task`1 System.Threading.Tasks.Task`1[[System.Collections.Generic.IEnumerable`1[[PF.Model.Person, PF.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, […]