분야 구동 디자인 사례의 업무 실현1

2916 단어
업무상 주로 제품의 창설, 고객의 창설, 주문을 하는 업무를 실현한다. 여기서 주로 분야 구동 디자인의 사상과 최상의 실천이 분야의 실현에 어떻게 구현되는지, 코드 중의 일부를 보여준다.
버그나 흠집은 너무 신경 쓰지 마세요.
DDD.Doman 프로젝트에서 해당 집합 루트, 솔리드 및 값 객체를 구현합니다.
이 글은 주로 고객의 창설을 실현한다. 모델-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;
        }
    }

좋은 웹페이지 즐겨찾기