gpt4 book ai didi

c# - 使用 CaSTLe 动态代理拦截所有依赖项

转载 作者:太空宇宙 更新时间:2023-11-03 22:55:02 25 4
gpt4 key购买 nike

我在我的代码中使用了 CaSTLe Dynamic Proxy 拦截器(用于记录目的)。我知道如何在依赖项上设置拦截器,就像这样:

      container.Register(Component.For<MyService>().
Interceptors<LoggerInterceptor>());

但是我如何将这个拦截器设置为所有我的依赖项?

最佳答案

在你对你的组件进行任何注册之前,你可以添加一个处理程序,它将你的拦截器添加到每个组件:

        container.Kernel.ComponentRegistered += (key, handler) =>
{
handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(LoggingInterceptor)));
};

关于c# - 使用 CaSTLe 动态代理拦截所有依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45820963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com