温莎城堡-短暂的生活方式释放拦截器 [英] Castle Windsor - Releasing Interceptor with Transient Lifestyle

查看:76
本文介绍了温莎城堡-短暂的生活方式释放拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档中进行了说明您应该始终使拦截器处于瞬态状态。如果我有此示例代码;

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()
                );

我应该担心释放 SampleInterceptor 还是容器释放 Sample.Component 中的服务后,它将自动释放吗?

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

这篇关于温莎城堡-短暂的生活方式释放拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆