Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Castle Windsor - Releasing Interceptor with Transient Lifestyle

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?

like image 393
soya Avatar asked Jul 06 '12 06:07

soya


1 Answers

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

like image 195
Krzysztof Kozmic Avatar answered Jan 03 '23 00:01

Krzysztof Kozmic