-
Notifications
You must be signed in to change notification settings - Fork 0
Dependency Injection
Every registration extension lives in the Pool namespace. The pool, its factory, its preparation strategy, and its metrics register as singletons. This page lists each extension and what it adds; the guides cover when to reach for each.
IServiceCollection AddPool<TPoolItem>(
this IServiceCollection services,
IConfiguration configuration,
Action<PoolOptions>? configureOptions = null)
where TPoolItem : class;Registers IPool<TPoolItem>, its validated PoolOptions, and the default metrics. Binds PoolOptions from the "PoolOptions" configuration section, then applies configureOptions. Also registers the default factory and preparation strategy when UseDefaultFactory and UseDefaultPreparationStrategy are set on the bound options. The options pipeline validates data annotations and runs ValidateOnStart, so an invalid value fails at host startup.
IServiceCollection AddPoolItemFactory<TPoolItem, TItemFactory>(this IServiceCollection services)
where TPoolItem : class
where TItemFactory : class, IItemFactory<TPoolItem>;Registers a custom item factory as a singleton. Call it before AddPool; it takes the place of the default factory.
IServiceCollection AddPreparationStrategy<TPoolItem, TPreparationStrategy>(this IServiceCollection services)
where TPoolItem : class
where TPreparationStrategy : class, IPreparationStrategy<TPoolItem>;Registers a custom preparation strategy as a singleton. Call it before AddPool; it takes the place of the default strategy.
IServiceCollection AddDefaultPoolMetrics<TPoolItem>(this IServiceCollection services)
where TPoolItem : class;Registers IPoolMetrics with the default implementation. AddPool calls this for you; use it directly only when you construct a pool without AddPool. See Metrics.
IServiceCollection AddPoolFactory<TPoolItem>(this IServiceCollection services)
where TPoolItem : class;Registers IPoolFactory<TPoolItem>, which resolves named pools by service key. AddNamedPool calls this for you.
IServiceCollection AddNamedPool<TPoolItem>(
this IServiceCollection services,
string name,
IConfiguration configuration,
Action<PoolOptions>? configureOptions = null)
where TPoolItem : class;Registers a named IPool<TPoolItem>, keyed by ServiceKey.Create<TPoolItem>(name). Binds the shared "PoolOptions" section, then the per-pool "{key}_PoolOptions" section, then applies configureOptions. See Named pools.
IServiceCollection AddPool<TPoolItem, TClient>(
this IServiceCollection services,
IConfiguration configuration,
Action<PoolOptions>? configureOptions = null,
Action<TClient>? configureClient = null)
where TPoolItem : class
where TClient : class;Registers a named pool keyed by the client type's full name and a TClient with that pool injected into its constructor. configureClient runs against the resolved client. Inject TClient directly to use its dedicated pool.
These extensions register an unbounded pool behind the same IPool<TPoolItem> surface. They parallel the bounded Add* methods but bind UnboundedPoolOptions and back the registration with UnboundedPool<TPoolItem>.
IServiceCollection AddUnboundedPool<TPoolItem>(
this IServiceCollection services,
IConfiguration configuration,
Action<UnboundedPoolOptions>? configureOptions = null)
where TPoolItem : class;Registers IPool<TPoolItem>, its validated UnboundedPoolOptions, and the default metrics. Binds UnboundedPoolOptions from the "UnboundedPoolOptions" configuration section, then applies configureOptions. Registers the default factory and preparation strategy when UseDefaultFactory and UseDefaultPreparationStrategy are set. The counterpart to AddPool.
IServiceCollection AddNamedUnboundedPool<TPoolItem>(
this IServiceCollection services,
string name,
IConfiguration configuration,
Action<UnboundedPoolOptions>? configureOptions = null)
where TPoolItem : class;Registers a named unbounded pool, keyed by ServiceKey.Create<TPoolItem>(name) and resolved through IPoolFactory<TPoolItem>. Binds the shared "UnboundedPoolOptions" section, then the per-pool "{key}_UnboundedPoolOptions" section, then applies configureOptions. The counterpart to AddNamedPool.
IServiceCollection AddUnboundedPool<TPoolItem, TClient>(
this IServiceCollection services,
IConfiguration configuration,
Action<UnboundedPoolOptions>? configureOptions = null,
Action<TClient>? configureClient = null)
where TPoolItem : class
where TClient : class;Registers a named unbounded pool keyed by the client type's full name and a TClient with that pool injected into its constructor. configureClient runs against the resolved client. The counterpart to AddPool<TPoolItem, TClient>.
IServiceCollection AddDefaultUnboundedPoolMetrics<TPoolItem>(this IServiceCollection services)
where TPoolItem : class;Registers IPoolMetrics named for the unbounded pool. AddUnboundedPool calls this for you; use it directly only when you construct an UnboundedPool<TPoolItem> without the registration extension. See Metrics.
string ServiceKey.Create<TPoolItem>(string name) where TPoolItem : class;Builds the key a named pool is registered under, of the form "{name}.{typeof(TPoolItem).Name}.Pool". Use it to resolve a pool through IPoolFactory<TPoolItem>.CreatePool rather than formatting the string by hand.