Skip to content

Pool Options

Mark Lauter edited this page Jun 15, 2026 · 2 revisions

Pool options

PoolOptions sets a pool's sizing, timeouts, and which built-in strategies to register. Bind it from the "PoolOptions" configuration section, pass an Action<PoolOptions>, or both — the action runs after binding. The options are validated through the data-annotation pipeline and checked at host startup, so an out-of-range value fails fast.

services.AddPool<SmtpConnection>(configuration, options =>
{
    options.MinSize = 2;
    options.MaxSize = 10;
    options.LeaseTimeout = TimeSpan.FromSeconds(30);
});

Sizing

MinSize

public int MinSize { get; set; }   // default 0, must be >= 0

Items created up front when the pool is built, and the floor Clear() refills to. When MinSize exceeds MaxSize, the pool seeds MaxSize items.

MaxSize

public int MaxSize { get; set; }   // default 100, must be >= 1

Hard cap on items in existence, and therefore on concurrent leases. Set to int.MaxValue for an effectively unbounded pool.

Timeouts

Each timeout defaults to Timeout.InfiniteTimeSpan (wait forever).

LeaseTimeout

public TimeSpan LeaseTimeout { get; set; }   // default infinite

How long a lease waits for an available item before throwing TaskCanceledException. With the default, a saturated pool waits indefinitely.

PreparationTimeout

public TimeSpan PreparationTimeout { get; set; }   // default infinite

How long the readiness check and preparation may take, combined. Applies only when a preparation strategy is registered.

IdleTimeout

public TimeSpan IdleTimeout { get; set; }   // default infinite

How long an item may sit idle before the next lease discards and disposes it instead of reusing it. Eviction is lazy: it happens when a lease meets the stale item, not on a background timer.

Default strategy registration

These flags control whether AddPool registers the built-in factory and preparation strategy. Both default to false.

UseDefaultFactory

public bool UseDefaultFactory { get; set; }   // default false

Registers the default item factory, which resolves TPoolItem from the service provider. Register the item type as well when you set this.

UseDefaultPreparationStrategy

public bool UseDefaultPreparationStrategy { get; set; }   // default false

Registers the default preparation strategy, which reports every item ready without a check.

Named-pool configuration

A named pool reads an optional per-pool section, "{key}_PoolOptions", layered over the shared "PoolOptions" section. The shared section binds first, the per-pool section overrides per property, and the configure action runs last.

Clone this wiki locally