-
Notifications
You must be signed in to change notification settings - Fork 0
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);
});public int MinSize { get; set; } // default 0, must be >= 0Items created up front when the pool is built, and the floor Clear() refills to. When MinSize exceeds MaxSize, the pool seeds MaxSize items.
public int MaxSize { get; set; } // default 100, must be >= 1Hard cap on items in existence, and therefore on concurrent leases. Set to int.MaxValue for an effectively unbounded pool.
Each timeout defaults to Timeout.InfiniteTimeSpan (wait forever).
public TimeSpan LeaseTimeout { get; set; } // default infiniteHow long a lease waits for an available item before throwing TaskCanceledException. With the default, a saturated pool waits indefinitely.
public TimeSpan PreparationTimeout { get; set; } // default infiniteHow long the readiness check and preparation may take, combined. Applies only when a preparation strategy is registered.
public TimeSpan IdleTimeout { get; set; } // default infiniteHow 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.
These flags control whether AddPool registers the built-in factory and preparation strategy. Both default to false.
public bool UseDefaultFactory { get; set; } // default falseRegisters the default item factory, which resolves TPoolItem from the service provider. Register the item type as well when you set this.
public bool UseDefaultPreparationStrategy { get; set; } // default falseRegisters the default preparation strategy, which reports every item ready without a check.
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.