Pooling of Context instances
Is your feature request related to a specific problem? Or an existing feature? Please describe.
We have noticed increased allocations related to creating the Context object. This can be easily avoided if Pollu provides built-in support for pooling or at least slightly change the internal implementation of Context so we can easily reset it to default state.
Currently, this is not achievable because of these read-only properties:
OperationIdCorrelationId
Describe your proposed or preferred solution:
We want to extend the Context API with the following static methods:
public static Context Get();
public static Context Get(string operationName);
public static void Return(Context context);
Alternatively, we can introduce a new ContextPool static class.
The pool can be also used internally to improve Polly performance.
Describe any alternative options you've considered:
Simpler solution is to make the following changes to Context class:
protected Guid? CorrelationIdField { get; protected set; }
public string OperationKey { get; protected set; }
We would just derive from Context and handle the pooling ourselves.
Any additional info?
For pooling support, we need implementation of the pool, and we can either:
- Include reference to Microsoft.Extensions.ObjectPool
- Implement our own pool (copy + paste) if additional dependencies are a no-go