Business implementation of domain-driven design cases 1

Source: Internet
Author: User

Business mainly to achieve product creation, customer creation, the business of placing orders, here the main demonstration of the field-driven design ideas and some of the best practices embodied in the implementation of the domain, some of the code

Bugs or blemishes don't have to be too much of a bother.

Implement the corresponding aggregate root, entity, and value objects in the Ddd.doman project.

This article mainly implements the creation of the customer, because the domain model has been established through Model-first, so we set up the partial class to implement the business logic part of the domain object.

 Public Partial classCustomer:aggreateroot {PrivateIrepository<customer>irepository;  PublicCustomer (irepository<customer>irepository) {             This. IRepository =irepository; }         Public voidCreateCustomer (stringNamestringMobilestringStatestringCity ,stringStreet) {Customer Customer=NewCustomer (); Customer. Id=Base.            Id; Customer. Name=name; Customer. Mobile=Mobile;            Addcustomeraddress (Customer, state, city, Street); IRepository.        Create (customer); }        Private voidAddcustomeraddress (Customer customer,stringStatestringCitystringStreet) {            varAddress =NewAddress (state, city, Street); Customer.        Address.add (address); }         Public voidAddcustomerotheraddress (Customer customer,stringStatestringCity ,stringStreet)            {addcustomeraddress (Customer, state, city, Street); IRepository.        Update (customer); }         PublicCustomer Getcustomerbyname (stringname) {            returnIRepository. Getbycondition (p = p.name = =name).        FirstOrDefault (); }    }
 Public Partial class Address:valueobject    {        public Address (string state,string city ,string  Street)        {              This Base . Id;             this. state = State ;             this. City = City ;             this. Street = Street;        }    }

Business implementation of domain-driven design cases 1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.