Ok, so most of you seem to be using an envelope wrapping the command.
As long as the data in this envelope is provided by the command
handling pipeline (not the command sender) it reckon it is more or
less the same thing as the context thingy I described. The difference
is that the envelope wraps the command while the context is provided
side-by-side. (Or are any of you in some way explicitly creating the
envelope in the command sender, e.g., a MVC-controller?)
A context is nice because because you don't have to look at it/go
through it to access the command. Most of the out-of-band data, e.g.
the user's IP address, is not interesting to look at in most command
handlers anyway. The envelope on the other hand keeps everything
together in a nice way.
So sending an envelope as a second parameter should conceptually be
the same as sending context as a second parameter (?).
On the query side I'm currently using standard methods (query
interfaces) which seem to be the most common approach, e.g:
public SomeThingDTO GetSomeThing(Guid thingId)
{
...use QueryContext.Current.UserId, e.g., to do authorization
....if ok, get something...
}
Of course, the context could also be sent as a parameter, although it
does not look as nice and clutters the interface imho. Enforcing
authorization through the "one view per user role" is interesting but
I'm not sure it would work in my case where the authorization is quite
complex (there would be too many views).
Envelopes won't work here since there is nothing to wrap unless a
handler-based approach with query messages is used instead, analogous
to command handlers and command messages. Anyone doing this? (Neil,
were you using context on the query side because of this or for some
other reason?)
I realize most of this is really not-so-implementation details and
mostly a matter of taste - but it is still interesting to hear how you
do it - it helps to to minimize development friction!