【发布时间】:2011-02-09 10:00:11
【问题描述】:
我目前正在使用 Autofac-1.4.5.676、autofac contrib 和城堡 DynamicProxy2 进行一些试验。目标是创建一个粗粒度分析器,可以拦截对特定接口的特定方法的调用。
问题:除了选择性部分之外,我的一切都完美无缺。我可能是错的,但我认为我需要将我的拦截器与 IProxyGenerationHook 实现结合起来,但我不知道该怎么做。
我的代码如下所示:
要截取&profile的接口(注意我只关心profile 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 困住了。
【问题讨论】:
标签: c# autofac castle-dynamicproxy