如何使用通用组件安装(方法)拦截器

发布于 2024-10-02 10:57:23 字数 468 浏览 0 评论 0原文

给出以下代码:

    container.Register(
            AllTypes.FromAssemblyNamed("MyNameSpace")
                    .Where(component => component.Name.EndsWith("Repository"))
                    .WithService.FirstInterface()
                    .Configure(component => component.LifeStyle.Singleton)
        );

是否可以为找到的所有组件引入拦截器(例如 LoggingInterceptor)?我现在唯一的办法是破坏每个组件并显式添加拦截器,我发现这违反直觉,因为他们将使用一个拦截器(即 LoggingInterceptor)。

谢谢

Given the following code:

    container.Register(
            AllTypes.FromAssemblyNamed("MyNameSpace")
                    .Where(component => component.Name.EndsWith("Repository"))
                    .WithService.FirstInterface()
                    .Configure(component => component.LifeStyle.Singleton)
        );

Is it possible to introduce an Interceptor(eg LoggingInterceptor) for all components found? My only recourse now is to break each components and add the Interceptor explicitly, which I found counter intuitive since they'll be using one interceptor(ie LoggingInterceptor).

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2024-10-09 10:57:23
container.Register(
                AllTypes.FromAssemblyNamed("MyNameSpace")
                        .Where(component => component.Name.EndsWith("Repository"))
                        .WithService.FirstInterface()
                        .Configure(component => component.LifeStyle.Singleton.Interceptors(InterceptorReference.ForType<LoggingInterceptor>()))
            );
container.Register(Component.For<LoggingInterceptor>());
container.Register(
                AllTypes.FromAssemblyNamed("MyNameSpace")
                        .Where(component => component.Name.EndsWith("Repository"))
                        .WithService.FirstInterface()
                        .Configure(component => component.LifeStyle.Singleton.Interceptors(InterceptorReference.ForType<LoggingInterceptor>()))
            );
container.Register(Component.For<LoggingInterceptor>());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文