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


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

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

     欢迎加入QQ讨论群:309287205

  • 相关阅读:
    Linux终端基本命令
    Markdown基本语法
    谷歌浏览器解决”此Flash Player与您的地区不相容“
    谷歌浏览器不可以默认允许flash的解决方法
    MySQL8.0登陆方式
    谷歌浏览器安装位置自定义
    java生成六位验证码
    对AJAX的理解
    对servlet请求的理解
    js60秒倒计时
  • 原文地址:https://www.cnblogs.com/malaoko/p/5050111.html
Copyright © 2020-2023  润新知