dolittle-obsolete / DotNET.Fundamentals

Reusable, fundamental abstractions and building blocks
http://www.dolittle.io
MIT License
4 stars 8 forks source link

IExecutionContextManager method isn't very descriptive #201

Open smithmx opened 5 years ago

smithmx commented 5 years ago

When we need to set the context (usually in service classes which aren't per request lifetime) then we call:

_executionContextManager.CurrentFor(tenantId, some_correlation_id);

It feels out of place and it isn't immediately obvious when it's being called (or that setting is a side-effect of getting the "current").

How about something like

using(_executionContextManager.SetScope(tenantId,correlationId)) { //do stuff }

It's not a disposable in the strict sense but it helps reinforce what's happening.

┆Issue is synchronized with this Asana task

einari commented 5 years ago

Agree. Name has much to be desired. Having it scoped with a using statement is not something that would be viable for some of the places we need it. It basically sets the current async context and relies on anything in that context to now be relative to the scope configured. But in some cases it could be very useful to have the possibility to enter a scope and exit it, an object implementing IDisposable would then keep track of the scope before and could pop it back when being disposed of.