17 Domain Services

WHAT’S IN THIS CHAPTER?

  • An introduction to domain services
  • A disambiguation from other types of service
  • Advice about when to consider using domain services
  • Examples of domain services for a variety of domains
  • A discussion, with several examples and techniques, on how to use domain services from within the application layer and the domain model

Wrox.com Code Downloads for This Chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/go/domaindrivendesign on the Download Code tab. The code is in the Chapter 17 download and individually named according to the names throughout the chapter.

When building domain models, you sometimes come across concepts or behavior that do not logically sit comfortably within an entity or aggregate in the system. This is an implicit sign that you may need to create a domain service.

Confusingly, service is an overloaded term. Fortunately, though, domain services are easily distinguished based on two defining characteristics: they represent domain concepts, and they are stateless. You are most likely to use domain services to orchestrate entities and encapsulate business policies rather than carry out infrastructural plumbing; leave that to application services.

In this chapter, you learn how to build domain services that cater to different scenarios. These scenarios include exposing domain services as contracts that are implemented outside the domain model, and building pure domain services that contain ...

Get Patterns, Principles, and Practices of Domain-Driven Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.