I 'm trying to do the following :

public class Ref
{
    public int RefCount;
    public object Target;
}

public class OneReferencePerThreadLifestyleManager :
AbstractLifestyleManager
{
    private readonly Dictionary<long, Ref> references = new
Dictionary<long, Ref>();
    private static long Key() { return
Thread.CurrentThread.ManagedThreadId; }

    public override object Resolve(CreationContext context)
    {
        if (!references.ContainsKey(Key()))
            references.Add(Key(), new Ref());
        Ref reference = references[Key()];
        if (reference.RefCount == 0)
            reference.Target = base.Resolve(context);
        reference.RefCount++;
        return reference.Target;
    }

    public override bool Release(object instance)
    {
        Ref reference = references[Key()];
        reference.RefCount--;
        if (reference.RefCount == 0)
        {
            reference.Target = null;
            references.Remove(Key());
            return base.Release(instance);
        }
        return true;
    }

    public override void Dispose()
    {
        references.ForEach(kv =>
Kernel.ReleaseComponent(kv.Value.Target));
    }
}

Release() however is only called once, even if I resolve more than one
instance...
Any ideas how to get something like this working ?

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to