MSL.Pool 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package MSL.Pool --version 1.0.3
NuGet\Install-Package MSL.Pool -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MSL.Pool" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MSL.Pool --version 1.0.3
#r "nuget: MSL.Pool, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MSL.Pool as a Cake Addin
#addin nuget:?package=MSL.Pool&version=1.0.3

// Install MSL.Pool as a Cake Tool
#tool nuget:?package=MSL.Pool&version=1.0.3

pool logo

Pool

A general purpose pool for items that may require initialization such as SMTP or database connections.

Lease / Release Pattern

Pooled items are placed on a queue. When a lease is requested, the pool attempts to dequeue an item. If it can, the item is returned on a task. If the item queue is empty, and the pool size is maxed out, then the lease request is queued and the lease request's TaskCompletionSource.Task is returned to the caller. The caller will block on await until timing out, or until another thread releases an item by calling Release, which scans the lease request queue for active requests before pushing the item back onto item queue.

Pool Item Factory

The pool item factory interface makes it possible to create new items for the pool and make items ready for use if they are not ready. There's a default pool implementation that uses IServiceProvider to construct items, but you can write your own factory implementation.

Ready Checker

The ready checker makes it possible to ensure items are ready for use before they are leased. This is useful for items that may become inactive after a period of time, such as a database connection that has been idle for a while.

Pool

The pool uses the item factory and the ready checker to create and manage item readiness. For example, if you pool a database or SMTP connection, the lease operation would include pulling a connection off the queue or constructing it if the queue is empty, then checking that the connection is active, and calling connect if the connection is inactive.

Dependency Injection

The ServiceCollectionExtensions class is in the Pool.DependencyInjection namespace.

  • Call AddPool<TPoolItem, TFactoryImplementation> to register a singleton pool with your own item factory implementation.
  • Call AddPoolWithDefaultFactory<TPoolItem> to register a singleton pool with the default item factory. The default factory uses the service provider to construct pool items.
  • Call AddReadyCheck<TPoolItem, TReadyCheck> to register your own IReadyCheck implementation. If a ready check is not registered, the pool will not check item readiness before leasing.

Dev Log

  • 12 FEB 2024 - started SMTP pool at the end of 2023, but got busy with other stuff. Will take it up again soon though because I need it for a work project.
  • 05 MAY 2024 - prepping for publish to Nuget.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 81 5/18/2024
1.1.1 88 5/18/2024
1.1.0 82 5/16/2024
1.0.5 77 5/16/2024
1.0.4 90 5/7/2024
1.0.3 94 5/7/2024
1.0.2 91 5/6/2024