CallContext - What are the recommendations for using this going forwards?

840 views Asked by At

Does anyone know if there's any planned support in upcoming versions of .NET for storing objects in the ambient execution context? There's a definite need for it, as highlighted in the following pages:

Limitations of CallContext: https://connect.microsoft.com/VisualStudio/feedback/details/276325/provide-better-context-support-to-async-operations

Implicit vs Explicit Context: http://msmvps.com/blogs/jon_skeet/archive/2010/11/08/the-importance-of-context-and-a-question-of-explicitness.aspx

The types of object which could be added to ambient execution context are:

  • Those which are not suitable for DI. I.e. extrinsic dependencies which should be defined by the call-site, but cross-cut the application-domain in a way which makes them impractical to be passed as method arguments. Examples: CancellationToken, IProgress, Transactions, SynchronizationContext, SecurityContext. (In fact, ExecutionContext has been hardcoded to pass the latter 2 around... any good reason why an open collection cannot be exposed for custom code?)
  • Those which are used by generic code emitted into method bodies... code which has no knowledge about the explicit dependencies available to it as arguments on the housing method, or properties of its declaring type. Consider PostSharp Aspects in the AOP world.

Would be great to hear people's thoughts on this one :)

EDIT: Have posted question here too: http://social.msdn.microsoft.com/Forums/en-US/async/thread/ea21ca57-5340-439c-8ee9-f0185b5787a1

0

There are 0 answers