dotnet / dotnet/aspnetcore

Feature Request: Integrate ObjectPool into Dependency Injection

Open
#55,367 6 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Right now if a service/etc wants to use an object from a `Microsoft.Extensions.ObjectPool`, it needs to know it's getting a pooled object.

There's also no way to customize service resolution and dispose behavior of the dependency injection machinery.

### Describe the solution you'd like

Provide a way to automatically resolve a service from an object pool and return at the end of a scope (checking `IResettable.TryReset` if applicable). Perhaps something like a `.AddPooled( maxCount: 10 )` as an alternative to `.AddScoped()`.

Or at least provide customization hooks in the DI machinery so we can implement this ourselves.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.