2012-01-05 61 views
1

在解决相关组件的任何实例后,是否有任何简单的方法可以在我的IInterceptor上获取方法?有点像IOnBehalfAware,但这样它会被实际的组件实例调用,而不是ComponentModel。在组件实例上调用城堡拦截器

+0

究竟你想做什么,为什么? – 2012-01-05 11:00:57

+0

我对截取的组件的成员(属性)有一些属性。我希望我的拦截器能够反映我的组件,并在解决问题后立即应用一些逻辑,然后存储结果。我不能使用常规的OnCreate委托,因为相同的IInterceptor实例在它拦截方法调用时稍后需要该数据。 – Jeff 2012-01-05 15:37:02

回答

0

结束了做这样的事情...定义一个接口,我IInterceptor(S)执行:

public interface IInstanceAware 
{ 
    void Execute(object instance); 
} 

然后注册组件(S)时,做

registration.OnCreate((kernel, instance) => 
{ 
    var accessor = instance as IProxyTargetAccessor; 
    foreach(var instanceAware in accessor.GetInterceptors().OfType<IInstanceAware>()) 
    { 
     accessor.Execute(instance); 
    } 
};