Skip to content

Execution Context

Do you want to get certain bits of contextual data without having to muck up your data? For that matter, if you’re using HTTP OpenApi generation, how would you even do that? Enter Request Contexts. These are basically dictionaries of objects that allow middleware to set pieces of data you may be interested in.

Some Examples

  • Is this data coming from the cache? If so, when is it from?
  • Is this data coming from the offline store? If so, when was it last updated?
  • There was an error that user notification trapped, we displayed it to the user and logged it, but maybe I want to do a little more processing on that Exception

How to use

IMediator mediator; // injected
var response = mediator.RequestWithContext(myRequest, CancellationToken.None);
response.Result // your result
response.Context.Values // the dicationy of objects

Events

Events have an aggregated context due to multiple sets of a middleware running against each event handler

Publish will return an EventAggregatedExecutionContext object by default now.

IMediator mediator; // injected
var aggregateContext = mediator.Publish(myEvent, CancellationToken.None);
foreach (var context in aggregateContext.Contexts)
{
// do something with the context
context.Values // the dictionary of values
}

Current Table of Values

TODO REQUESTS

  • Caching
  • Offline
  • User Error Notifications

EVENTS

  • Event Exception Handler