I think you would have to call Release on the resolved components at the end of the thread. See http://stw.castleproject.org/Windsor.Release-Policy.ashx
Anyway, can you elaborate on the purpose of OneReferencePerThreadLifestyleManager ? I don't any reason to limit references per thread... Cheers, Mauricio On Tue, Jul 6, 2010 at 7:25 AM, kilfour <[email protected]> wrote: > 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]<castle-project-users%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/castle-project-users?hl=en. > > -- 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.
