Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 在组件实例上调用Castle拦截器_.net_Castle Windsor_Castle Dynamicproxy - Fatal编程技术网

.net 在组件实例上调用Castle拦截器

.net 在组件实例上调用Castle拦截器,.net,castle-windsor,castle-dynamicproxy,.net,Castle Windsor,Castle Dynamicproxy,有没有什么简单的方法可以让我的IInterceptor上的方法在相关组件的任何实例被解析后立即被调用?有点像IOnBehalfAware,但它是通过实际的组件实例而不是组件模型来调用的。最后做了这样的事情…定义一个接口,我的IInterceptors实现: public interface IInstanceAware { void Execute(object instance); } 然后在注册组件时,执行以下操作: registration.OnCreate((kernel, i

有没有什么简单的方法可以让我的IInterceptor上的方法在相关组件的任何实例被解析后立即被调用?有点像IOnBehalfAware,但它是通过实际的组件实例而不是组件模型来调用的。

最后做了这样的事情…定义一个接口,我的IInterceptors实现:

public interface IInstanceAware
{
   void Execute(object instance); 
}
然后在注册组件时,执行以下操作:

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

你到底想做什么?为什么?我在截获组件的members属性上有一些属性。我希望我的拦截器在我的组件上进行反思,并在解析后应用一些逻辑,然后存储结果。我不能使用常规的OnCreate委托,因为同一个IInterceptor实例稍后在拦截方法调用时需要该数据。