Transient interceptors not being released

39 views
Skip to first unread message

Vladimir Okhotnikov

unread,
Nov 6, 2012, 3:59:35 AM11/6/12
to castle-pro...@googlegroups.com
Hi

I have a following failing test in an empty project with Windsor 3.1 from NuGet:

[Test]
public void TransientInterceptor()
{
var interceptorCreated = false;
var interceptorReleased = false;

var c = new DefaultKernel();
c.ComponentCreated += (model, instance) =>
{
if (model.Implementation == typeof(AnInterceptor))
{
interceptorCreated = true;
}
};
c.ComponentDestroyed += (model, instance) =>
{
if (model.Implementation == typeof(AnInterceptor))
{
interceptorReleased = true;
}
};

c.Register(
Component.For<AComponent>().LifeStyle.Transient,
Component.For<AnInterceptor>().LifeStyle.Transient);

var component = c.Resolve<AComponent>();
c.ReleaseComponent(component);

Assert.IsTrue(interceptorCreated);
Assert.IsTrue(interceptorReleased);
}

public class AnInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
invocation.Proceed();
}
}

[Interceptor(typeof(AnInterceptor))]
public class AComponent
{
public virtual void Intercepted()
{
}
}

The test fails on the very last line, i.e. ComponentDestroyed for the interceptor is never being called. Is it a bug or am I missing something?

Regards,
Vladimir Okhotnikov

Vladimir Okhotnikov

unread,
Nov 6, 2012, 4:04:07 AM11/6/12
to castle-pro...@googlegroups.com
Oops, forgot that microkernel does not work with interceptors. Still, this one fails:

        [Test]
        public void TransientInterceptor()
        {
            var interceptorCreated = false;
            var interceptorReleased = false;

            var c = new WindsorContainer();
            c.Kernel.ComponentCreated += (model, instance) =>
            {
                if (model.Implementation == typeof(AnInterceptor))
                {
                    interceptorCreated = true;
                }
            };
            c.Kernel.ComponentDestroyed += (model, instance) =>
            {
                if (model.Implementation == typeof(AnInterceptor))
                {
                    interceptorReleased = true;
                }
            };

            c.Register(
                Component.For<AComponent>().LifeStyle.Transient,
                Component.For<AnInterceptor>().LifeStyle.Transient);

            var component = c.Resolve<AComponent>();
            c.Kernel.ReleaseComponent(component);

            Assert.IsTrue(interceptorCreated);
            Assert.IsTrue(interceptorReleased);
        }

вторник, 6 ноября 2012 г., 10:59:53 UTC+2 пользователь Vladimir Okhotnikov написал:
Hi

I have a following failing test in an empty project with Windsor 3.1 from NuGet:

... 

Krzysztof Kozmic

unread,
Nov 6, 2012, 4:04:06 AM11/6/12
to castle-pro...@googlegroups.com
Vladimir,

your interceptor wasn't released, because it was never tracked in the first place.
It's not disposable, has no custom decommission steps, and no dependencies that requires decommission.


There's no reason for it to be tracked.


-- 
Krzysztof Kozmic

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

Vladimir Okhotnikov

unread,
Nov 6, 2012, 4:10:33 AM11/6/12
to castle-pro...@googlegroups.com
Indeed, adding IDisposable makes the test pass. Many thanks, Krzysztof

вторник, 6 ноября 2012 г., 11:04:17 UTC+2 пользователь Krzysztof Koźmic написал:
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages