Lagoon is an object pool. It pools objects that are expensive to initialize. Think database connections or network connections in general.
TBD. There will be a nuget package at some point.
using Lagoon;
var factory = new MyFactory(); // this is a factory for creating and activating your objects, implements IObjectPoolFactory
var pool = new DefaultObjectPool(factory);
using (var obj = await GetObjectAsync()) { // This will either grab an instance from the pool or create a new one.
// do something with the object
} // the object is not actually disposed, but returned to the pool.
pool.Dispose(); // the pool is disposed, also disposing all objects in the pool.
- The objects to be pooled must implement
IDisposable
. - The pool itself is meant to be used throughout your application.
This repo is a companion to a blog series about object pool patterns.