zoukankan      html  css  js  c++  java
  • 领域驱动设计案例之业务实现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

  • 相关阅读:
    LOJ-10096(强连通+bfs)
    LOJ-10095(缩点的特殊使用)
    LOJ-10094(强连通分量)
    LOJ-10092(最大半连通子图)
    【BZOJ3489】A simple rmq problem(KD-Tree)
    UVA10384 推门游戏 The Wall Pushers(IDA*)
    [SCOI2005]骑士精神(IDA*)
    浅谈A*算法
    【模板】K-D Tree
    【XSY1953】【BZOJ4012】【HNOI2015】开店(动态点分治)
  • 原文地址:https://www.cnblogs.com/malaoko/p/5050111.html
Copyright © 2011-2022 走看看