EsoxSolutions.ObjectPool 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package EsoxSolutions.ObjectPool --version 1.0.0
NuGet\Install-Package EsoxSolutions.ObjectPool -Version 1.0.0
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="EsoxSolutions.ObjectPool" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EsoxSolutions.ObjectPool --version 1.0.0
#r "nuget: EsoxSolutions.ObjectPool, 1.0.0"
#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 EsoxSolutions.ObjectPool as a Cake Addin
#addin nuget:?package=EsoxSolutions.ObjectPool&version=1.0.0

// Install EsoxSolutions.ObjectPool as a Cake Tool
#tool nuget:?package=EsoxSolutions.ObjectPool&version=1.0.0

EsoxSolutions.ObjectPool

Overview

Sometimes, for reasons of efficiency, it can be quite handy to keep a pool, that is non-empty set, of initialized objects ready. This can be the case in for instance when you have database connections, which are expensive to create both in time and resources.

What you do is that make a pool of objects, usually an array, and you have one object managing that array, giving out objects, and returning, basically doing the bookkeeping.

This is a very simple implementation of such a pool, which is thread safe, and can be used in a multi-threaded environment.

Caveat: I consider this version to be still in beta. If you find any bugs, please report them to me, or mail me at info@esoxsolutions.nl

Usage

There are two main classes:

  1. The PoolModel class which holds an object in a pool.
  2. The ObjectPool which releases and returns the PoolModel objects.

###PoolModel The PoolModel is a generic class. It takes a type parameter, which is the type of the object you want to pool. To get the value stored in the PoolModel, use the Unwrap method.

An example use:

            var initialObjects = new List<int> { 1, 2, 3 };
            var objectPool = new ObjectPool<int>(initialObjects);

            using (var model = objectPool.GetObject())
            {
                var value = model.Unwrap();
				Console.WriteLine(value);
            }

ObjectPool

The objectpool as you can see administers the object. In its constructor its gets a list of pre-initialized objects. The length of this list does not change. In case there are no more objects in the pool, an exception is raised.

Future work

One possible extension would be to have a timeout on the objects in the pool. If an object is not used for a certain amount of time, it is disposed. This would be useful in case you have a pool of database connections, and you want to make sure that the connections are not kept open for too long. Also it would be nice to have some sort of LINQ-query to get objects with certain values from the pool.

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.
  • net8.0

    • No dependencies.

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
1.1.5 190 11/19/2023
1.1.4 79 11/16/2023
1.1.3 91 11/16/2023
1.1.2 107 11/14/2023
1.1.1 100 11/13/2023
1.1.0 97 11/13/2023
1.0.2 95 11/13/2023
1.0.1 111 11/13/2023
1.0.0 104 11/13/2023

version 1.0: Beta