From UI to Commands - how?
| Newsgroups | gmane.comp.programming.domain-driven-design |
|---|---|
| Message-ID | <[email protected]> |
Hi
How do you map UI Changes to commands in your DDD application ?
With a typical web UI having a bunch of input fields the User needs to set, its tempting to just have a CRUD like Update Action on your resource oriented backend endpoint. (Who says it should be resource oriented btw)
http Put myApi/MyResource/resourceId
This would lead to a myAggregateRoot.Update method getting called.
As you may know this looses the intent o the user and creates an somewhat anemic domain model. We don't capture the behavior which forms our ubiquitous language.
Say the user wants to
1. Add subcontent to MYResource
2. Activate myResource
that would correspond to
myAggregateRoot.Add(newSubContent)
and
myAggregateRoot.Activate()
I see two ways to accomplish this
UI makes multiple requests
1 http Post myApi/MyResource/resourceId/Content
2 http Post myApi/MyResource/resourceId/Activation
Currently my UI would have multiple tasks/actions on one single page. two requests seems like
doing a chatty implementation. when actions could be batched and send in one request.
Of cause UI could be split up so each page only deals with a single task / action.
OR
put an update as a list of user activities (commands) to
http Put myApi/MyResource/resourceId/
or
http Post myApi/MyResource/resourceId/changes
the changes could have a json format like
{
updates:[
{
id : 2324234234,
occurred : some date,
name : AddContent
data : {
content goes here
}
},
{
id : 2324234234,
occurred : some date,
name : Activate
data : {}
}
}
]
}
this could be mapped to commands in the application layer in a generic way.
But it would require the UI guys to work in a different way.
What do you think ?
Cheers Christian