6

文档中指出,您应该始终使拦截器成为瞬态。如果我有这个示例代码;

//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在容器释放服务后自动释放?

4

1 回答 1

9

您的瞬态拦截器将其生命周期绑定到您与之关联的对象,并且当该对象作为该对象图表的任何其他部分被释放时将被释放

于 2012-07-06T08:57:19.680 回答