我目前正在使用 Autofac-1.4.5.676、autofac contrib 和 castle DynamicProxy2 进行一些试验。目标是创建一个粗粒度分析器,可以拦截对特定接口的特定方法的调用。
问题:除了选择性部分之外,我的一切都完美无缺。我可能是错的,但我认为我需要将我的拦截器与 IProxyGenerationHook 实现结合起来,但我不知道如何做到这一点。
我的代码看起来像这样:
被截取&剖析的接口(注意我只关心剖析Update()方法)
public interface ISomeSystemToMonitor
{
void Update(); // this is the one I want to profile
void SomeOtherMethodWeDontCareAboutProfiling();
}
现在,当我向容器注册我的系统时,我执行以下操作:
// Register interceptor gubbins
builder.RegisterModule(new FlexibleInterceptionModule());
builder.Register<PerformanceInterceptor>();
// Register systems (just one in this example)
builder.Register<AudioSystem>()
.As<ISomeSystemToMonitor>)
.InterceptedBy(typeof(PerformanceInterceptor));
所有从容器中拉出的 ISomeSystemToMonitor 实例都会根据需要被拦截和分析,除了它会拦截其所有方法,而不仅仅是 Update 方法。
现在,如何扩展它以排除 Update() 以外的所有方法?正如我所说,我不明白我要如何通知容器“对于 ProfileInterceptor,使用 IProxyHookGenerator 的这个实现”。
所有帮助表示赞赏,干杯!另外,请注意我现在无法升级到 autofac2.x;我被困在1。