标签:
业务上主要实现产品的创建,客户的创建、下订单的业务,这里主要演示领域驱动设计的思想与一些最佳实践如何体现到领域的实现中,代码中的一些
Bug或瑕疵不用太过理会。
在DDD.Doman项目中实现相应的聚合根、实体与值对象。
这篇文章主要实现客户的创建,因为通过Model-First已经建立了领域模型,所以我们建立分部类来实现领域对象的业务逻辑部分。
public partial class Customer:AggreateRoot { private IRepository<Customer> irepository; public Customer(IRepository<Customer> irepository) { this.irepository = irepository; } public void CreateCustomer(string name,string mobile,string state,string city, string street) { Customer customer = new Customer(); customer.Id = base.Id; customer.Name = name; customer.Mobile = mobile; addcustomeraddress(customer, state, city, street); irepository.Create(customer); } private void addcustomeraddress(Customer customer,string state,string city,string street) { var address = new Address(state, city, street); customer.Address.Add(address); } public void AddCustomerOtherAddress(Customer customer,string state,string city, string street) { addcustomeraddress(customer, state, city, street); irepository.Update(customer); } public Customer GetCustomerByName(string name) { return irepository.GetByCondition(p => p.Name == name).FirstOrDefault(); } }
public partial class Address:ValueObject { public Address(string state,string city,string street) { this.Id = base.Id; this.State = state; this.City = city; this.Street = street; } }
标签:
原文地址:http://www.cnblogs.com/malaoko/p/5050111.html