RSB + Castle Windsor: message consumers not being tracked/cleaned up

13 views
Skip to first unread message

Jakub Berezanski

unread,
Mar 26, 2012, 1:16:02 PM3/26/12
to rhino-t...@googlegroups.com

In CastleServiceLocator.cs, the code which resolves message consumers looks like this:

            return (from h in container.Kernel.GetAssignableHandlers(type)
                   select (IHandler)new DefaultHandler(h.Service, h.ComponentModel.Implementation, () => h.Resolve(CreationContext.CreateEmpty())));

The empty CreationContext references the NoTrackingReleasePolicy, which prevents message consumers (and their dependencies) from being cleaned up after message consumption (although RSB calls container.Kernel.ReleaseComponent(item), it has no effect since the object is not tracked).

In my scenario, a few message consumers need to call a WCF service, and receive a proxy to this service via constructor injection. The consumers themselves are simple classes that do not require cleanup. The proxy must be closed, however, and I wanted to implement the logic as an IDecommissionConcern. Unfortunately, the above problem prevents the cleanup code from being invoked.

I have implemented a fix, which creates a CreationContext that references the ReleasePolicy configured for the container:

                   () => h.Resolve(new CreationContext(h, container.Kernel.ReleasePolicy, type, null, null, null))

It seems to be working and tests are green. I'm curious, however, what was the original reason for using an empty CreationContext in the resolving code and whether the reason still stands (and I'm missing something)?

Reply all
Reply to author
Forward
0 new messages