Surface the _numItems as a public property on DefaultObjectPool #61029
Labels
api-ready-for-review
API is ready for formal API review - https://github.com/dotnet/apireviews
needs-area-label
Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
Background and Motivation
It would be nice to be able to emit a metric anytime the DefaultObjectPool limit is breached. Currently this is not possible because the
bool ReturnCore
is markedprivate protected
so it cannot be overridden to get thebool
response from this method. If the _numbItems was encapsulated as a Property {get}, than it would be possible to determine if the pool is full.Proposed API
public class DefaultObjectPool<T> : ObjectPool<T> where T : class { private readonly Func<T> _createFunc; private readonly Func<T, bool> _returnFunc; private readonly int _maxCapacity; private int _numItems; private protected readonly ConcurrentQueue<T> _items = new(); private protected T? _fastItem; + public int ItemCount => _numItems;
Usage Examples
Alternative Designs
private
from theprivate protected bool ReturnCore
so it can be overridden, call the base class to get the boolean response and emit the metric there.ObjectPool<T>.void Return(T obj)
toObjectPool<T>.bool Return(T obj)
Risks
The least risk is to expose the
int
property so that the underlying APIs to need to change. I don't foresee any risks by exposing theItemCount
property.The text was updated successfully, but these errors were encountered: