Rickard Öberg
2010-02-22 02:17:05 UTC
I am learning DDD but is somewhat confused about the difference between
Application Services and Domain Services.
I thought I understood Application Services that is fronts the Domain
Layer. My current understanding is that the Application Layer should not
contain any business rules and that it should be responsible for
specific application tasks. E.g. For example where the application is a
web service it would convert the web service data and calls and direct
it to the Domain Layer.
I would call that the "UI" layer, meaning, whatever it is that convertsApplication Services and Domain Services.
I thought I understood Application Services that is fronts the Domain
Layer. My current understanding is that the Application Layer should not
contain any business rules and that it should be responsible for
specific application tasks. E.g. For example where the application is a
web service it would convert the web service data and calls and direct
it to the Domain Layer.
the UI model (be it Swing, SOAP, JMS, etc.) to the application internal
model.
The Application Layer does this (DDD book, p.70):
"Defines the jobs the software is supposed to do and directs the
expressive domain objects to work out problems. The tasks this layer is
responsible for are meaningful to the business or necessary for
interactions with the application layers of other systems.
This layer is kept thin. It does not contain business rules or
knowledge, but only coordinates tasks and delegates work to
collaborations of domain objects in the next layer down. It does not
have state reflecting the business situation, but it can have state that
reflects the progress of a task for the user or the program."
There are a couple of ways to implement the application layer. One is to
use "application services", where the methods signify usecases. Another
approach that I'm personally growing very fond of is to use the DCI
pattern (complementary to MVC), which I have found significantly
simplifies my usecase code and permission checks, and such things. It
also happens to make it trivial to make REST API's properly.
<snip>
Here it seems that the Application Layer need to know a fair bit of what
is involved in booking new cargo, although arguably not that much and I
can still accept that is correct. But would the green section not make
more sense in the Domain Layer and make it still easier for the
Application Layer?
The really confusing part for me is the use of Repository access from
the Application layer and from the Domain layer.
Is the answer perhaps that the Domain layer should not be involved with
data access at all?
What I've found when using the DCI approach to the application layer,is involved in booking new cargo, although arguably not that much and I
can still accept that is correct. But would the green section not make
more sense in the Domain Layer and make it still easier for the
Application Layer?
The really confusing part for me is the use of Repository access from
the Application layer and from the Domain layer.
Is the answer perhaps that the Domain layer should not be involved with
data access at all?
the context will be doing the repository lookups, and the interaction
then triggers off the actual call into the domain model. I assume you'd
have to do something similar with an application service approach. So
yes, all lookups would be in the application layer, rather than the
domain layer.
/Rickard
------------------------------------