Skip to content
yanggujun edited this page Dec 30, 2019 · 6 revisions

Commons.Pool

Commons.Pool privdes a light weight and thread safe object pool implementation.

Installation

Commons.Pool is delivered as a nuget package. It requires "Commons" package. You can get the package from nuget.org and its dependency Commons

or you can directly install from nuget console by typing following commands:

PM>Install-Package Commons.Pool

Usage Guide

  • A light weight generic object pool.
    // When initializing the IoC container...
    IocContainer.Register<PoolManager>();

    //...
    // Somewhere in the application.
    var poolManager = IocContainer.Resolve<IPoolManager>();

    //...

    // Create a new pool.
    var sqlFactory = new DefaultDbConnectionFactory(connectionString);
    var connectionPool = poolManager.NewPool<IDbConnection>(c =>
                         {
                              c.InitialSize = 0;
                              c.MaxSize = 10;
                              c.ByFactory(sqlFactory);
                         });

    //...
    var connection = connectionPool.Acquire();

    // ...
    // use the connection.
    // ...

    connectionPool.Return(connection);
    //...


    // When pool manager is disposed, the pool is disposed too.
    poolManager.Dispose();

Clone this wiki locally