Castle Windsor - Releasing Interceptor with Transient Lifestyle
Asked Answered
C

1

6

It is stated in the documentation that you should always make interceptors transient. If I have this sample code;

//register interceptor
container.Register(Classes.FromAssemblyNamed("Sample.Interceptors")
.BasedOn<Castle.DynamicProxy.IInterceptor>()
.LifestyleTransient());

//Configure components to intercept
 container.Register(Classes.FromAssemblyNamed("Sample.Component")
.IncludeNonPublicTypes().InNamespace("Sample.Component", true)
            .Configure(c=>
                c.Interceptors(InterceptorReference.ForType<SampleInterceptor>())
                 .Anywhere.LifestyleSingleton())
                 .WithService.DefaultInterfaces()
                );

Should I worry about releasing SampleInterceptor, or will it be released automatically once the service in Sample.Component has been released by the container?

Corinnecorinth answered 6/7, 2012 at 6:11 Comment(0)
C
9

Your transient interceptor will have its lifespan bound to the object you associate it with, and will be released when that object gets released as any other part of that object's graph

Coucher answered 6/7, 2012 at 8:57 Comment(2)
I had a good feeling that this will be the behaviour of the transient interceptor, but it was not clearly described in the documentation. Thank you very much!Corinnecorinth
Feel free to update the documentation to make it clearer :) It's an open wikiCoucher

© 2022 - 2024 — McMap. All rights reserved.