1

There is a client-service application that uses WCF to build service-oriented architecture and DDD to build domain layer inside the service.

In the Domain Layer there is a domain object Customer with methods:

  1. to change Phone and Address Customer.Relocate(Phone, Address)
  2. to assign Sales Manager to a Customer Customer.Assign(SalesManager)
  3. to make Discount to a Customer Customer.Make(Discount)

Since this Domain Layer is used inside a WCF Service, CustomerService is created with service methods:

  1. CustomerService.Relocate(CustomerID, PhoneDTO, AddressDTO)
  2. CustomerService.Assign(CustomerID, SalesManagerID)
  3. CustomerService.MakeDiscount(DiscountDTO)

These methods validate parameters, request domain objects and invoke domain object methods to apply business logic.

The problem is that it looks like huge code duplication, since WCF Service methods are almost (90%) identical to methods of domain layer with parameters, expressed in IDs and DTOs.

  1. Is this method duplication always happening when WCF / SOA is used with DDD?
  2. Is there any way to make this thin WCF Service layer build automatically from Domain Layer?
  3. Any other ideas?
Lightman
  • 1,078
  • 11
  • 22
  • you service method signature and customer class method signatures are different. So It's ofcourse inevitable. Think of your service class as Adpater which does some manipulation on input and supply compatible input to Adaptee. – vendettamit Oct 22 '15 at 17:39

1 Answers1

2

This is by design. With DDD, domain logic is separated from application logic. Thus, there is no code duplication, because the two layers have different responsibilities.

Code that potentially could be duplicated are the validation rules: They are usually used in the domain layer to enforce invariants, and in the service layer to perform input validation. If this is the case in your application, you should refactor your code to remove the duplication and make the validation rules reusable. See also this answer.

If the problem that your software solves is so simple that the above still feels like repetitive work, DDD is probably not the right approach.

Community
  • 1
  • 1
theDmi
  • 17,546
  • 6
  • 71
  • 138