Repository navigation
"scoped instances" in Microsoft.Extensions.ObjectPool.DependencyInjection #4515
Unanswered
KalleOlaviNiemitalo
asked this question in
Q&A
Replies: 3 comments 2 replies
|
Re "is the implementation incomplete" — I thought maybe this library defines some class like public sealed class PooledObject<TService> : IDisposable
{
public TService Instance { get; }
public void Dispose(); // returns to the pool
}and then registers PooledObject<TService> as a scoped service so that it can be injected to constructors in a service scope, and the object is returned to the pool when the scope is disposed. ObjectPoolServiceCollectionExtensions doesn't register anything like that though, and the library never calls ObjectPool<TService>.Get or ObjectPool<TService>.Return. |
1 reply
|
Maybe it should say /// <summary>
/// Adds an <see cref="ObjectPool{TService}"/> from which instances of <typeparamref name="TService"/> can be borrowed.
/// </summary> |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The documentation of the Microsoft.Extensions.ObjectPool.ObjectPoolServiceCollectionExtensions.AddPooled methods mentions "scoped instances":
However, this is the only mention of "scoped" in the Microsoft.Extensions.ObjectPool.DependencyInjection project. Those methods register the ObjectPool<TService> service as a singleton; and when the DefaultObjectPool<TService> instance is created, its DependencyInjectionPooledObjectPolicy<TService, TImplementation> captures a reference to the IServiceProvider, which presumably is the root rather than any IServiceScope.ServiceProvider. If a scoped service were somehow injected to a pooled object, and the object kept a reference to the service, then it would not be safe to return the pooled object to the singleton pool, where it could outlive the service.
What then is the meaning of "scoped instances" here; is it just a documentation error, or is the implementation incomplete?
All reactions