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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With