views:

21

answers:

1

I've tried out the pooling lifestyle with Windsor.
Lets say I want multiple CustomerTasks to work with a pool of ILogger's.
when i try resolving more times than maxPoolSize, new loggers keeps getting created.

what am I missing and what exactly is the meaning of max pool size?

the xml configuration i use is (demo code):

<component id="customertasks" type="WindsorTest.CustomerTasks, WindsorTestCheck" lifestyle="transient" />
<component id="logger.console" service="WindsorTest.ILogger, WindsorTestCheck" type="WindsorTest.ConsoleLogger, WindsorTestCheck" lifestyle="pooled" initialPoolSize="2" maxPoolSize="5" />

Code is:

public interface ILogger
{
    void Log(string message);
}

public class ConsoleLogger : ILogger
{
    private static int count = 0;
    public ConsoleLogger()
    {
        Console.WriteLine("Hello from constructor number:" + count);
        count++;
    }

    public void Log(string message)
    {
        Console.WriteLine(message);
    }
}

public class CustomerTasks
{
    private readonly ILogger logger;

    public CustomerTasks(ILogger logger)
    {
        this.logger = logger;
    }
    public void SaveCustomer()
    {
        logger.Log("Saved customer");
    }
}
A: 

I have found this article in dotnetslackers that pretty much cleared things up for me.
maxPoolSize is the maximal number of instances that will be returned to the pool upon release. subsequent releases will result in objects being discarded.

one inaccuracy i've noticed is that initialPoolSize is the number of instances created upon first resolve and NOT container creation like the article claims (probably due to version changes since it was written)

AlonEl

related questions