Reputation: 63
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?
Upvotes: 6
Views: 679
Reputation: 27374
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
Upvotes: 9