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