码迷,mamicode.com
首页 > 其他好文 > 详细

领域驱动设计案例之业务实现1

时间:2015-12-16 09:31:57      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

 业务上主要实现产品的创建,客户的创建、下订单的业务,这里主要演示领域驱动设计的思想与一些最佳实践如何体现到领域的实现中,代码中的一些

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;
        }
    }

 

领域驱动设计案例之业务实现1

标签:

原文地址:http://www.cnblogs.com/malaoko/p/5050111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!