StrangeIoC  0.6.0
The IoC/Binding Framework for Unity3D and C#
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public Member Functions | Properties | List of all members
strange.extensions.pool.api.IPool Interface Reference

A mechanism for storing and reusing instances. More...

Inheritance diagram for strange.extensions.pool.api.IPool:
strange.framework.api.IManagedList strange.extensions.pool.api.IPool< T > strange.extensions.pool.impl.Pool strange.extensions.pool.impl.Pool< T > strange.extensions.pool.impl.Pool< T >

Public Member Functions

object GetInstance ()
 Gets an instance from the pool if one is available. More...
 
void ReturnInstance (object value)
 Returns an instance to the pool. More...
 
void Clean ()
 Remove all instance references from the Pool. More...
 
- Public Member Functions inherited from strange.framework.api.IManagedList
IManagedList Add (object value)
 Add a value to this List.
 
IManagedList Add (object[] list)
 Add a set of values to this List.
 
IManagedList Remove (object value)
 Remove a value from this List.
 
IManagedList Remove (object[] list)
 Remove a set of values from this List.
 

Properties

IInstanceProvider instanceProvider [get, set]
 A class that provides instances to the pool when it needs them. More...
 
Type poolType [get, set]
 The object Type of the first object added to the pool. More...
 
int available [get]
 Returns the count of non-committed instances More...
 
int size [get, set]
 Gets or sets the size of the pool. More...
 
int instanceCount [get]
 Returns the total number of instances currently managed by this pool. More...
 
PoolOverflowBehavior overflowBehavior [get, set]
 Gets or sets the overflow behavior of this pool. More...
 
PoolInflationType inflationType [get, set]
 Gets or sets the type of inflation for infinite-sized pools. More...
 
- Properties inherited from strange.framework.api.IManagedList
object value [get]
 Retrieve the value of this List. More...
 

Detailed Description

A mechanism for storing and reusing instances.

Unlike much of the rest of Strange, the Pool is not a Binder, per se. Rather, it holds onto instances created by other parts of your application for use and reuse. Strange applies Pools in the CommandBinder and EventDispatcher for the recycling of those instances. But you can employ Pools yourself by mapping and injecting a Pool for instances you want to reuse.

Basic instructions for injecting a Pool for use: Map IPool<SomeClass> in the InjectionBinder:

injectionBinder.Bind<IPool<MyClass>>().ToSingleton();

Then inject like so:

[Inject]
public IPool<MyClass> myPool { get; set; }

A couple of caveats for working with Pools:

  1. A limitation of the version of .NET currently used by Unity forbids using interfaces or abstracts in generics. so you cannot map and inject IPool<IMyInterface> or IPool<MyAbstractClass>. This is a little confusing in Strange, since we're used to mapping injections in exactly this fashion (e.g., injectionBinder.Bind<ISomeInterface>). The reason this doesn't work for Pools has to do with setting properties, rather than the binding itself. But because it will bite you, we throw an Exception if you attempt to Bind or set anything but a concrete Pool type.
  2. Pooling presupposes that when the instance is finished doing what it does it is cleaned up and returned to the Pool. Use IPool.ReturnInstance() to mark an object as ready for reuse.
    See Also
    strange.extensions.pool.api.IPoolable for more on cleaning up.

Member Function Documentation

void strange.extensions.pool.api.IPool.Clean ( )

Remove all instance references from the Pool.

Implemented in strange.extensions.pool.impl.Pool.

object strange.extensions.pool.api.IPool.GetInstance ( )

Gets an instance from the pool if one is available.

Returns
The instance.

Implemented in strange.extensions.pool.impl.Pool, strange.extensions.pool.api.IPool< T >, and strange.extensions.pool.impl.Pool< T >.

void strange.extensions.pool.api.IPool.ReturnInstance ( object  value)

Returns an instance to the pool.

If the instance being released implements IPoolable, the Release() method will be called.

Parameters
valueThe instance to be return to the pool.

Implemented in strange.extensions.pool.impl.Pool.

Property Documentation

int strange.extensions.pool.api.IPool.available
get

Returns the count of non-committed instances

PoolInflationType strange.extensions.pool.api.IPool.inflationType
getset

Gets or sets the type of inflation for infinite-sized pools.

By default, a pool doubles its InstanceCount.

A PoolInflationType value.

int strange.extensions.pool.api.IPool.instanceCount
get

Returns the total number of instances currently managed by this pool.

IInstanceProvider strange.extensions.pool.api.IPool.instanceProvider
getset

A class that provides instances to the pool when it needs them.

This can be the InjectionBinder, or any class you write that satisfies the IInstanceProvider interface.

PoolOverflowBehavior strange.extensions.pool.api.IPool.overflowBehavior
getset

Gets or sets the overflow behavior of this pool.

A PoolOverflowBehavior value.

Type strange.extensions.pool.api.IPool.poolType
getset

The object Type of the first object added to the pool.

Pool objects must be of the same concrete type. This property enforces that requirement.

int strange.extensions.pool.api.IPool.size
getset

Gets or sets the size of the pool.

The pool size. '0' is a special value indicating infinite size. Infinite pools expand as necessary to accomodate requirement.


The documentation for this interface was generated from the following file: