具有流畅界面的城堡拦截器
我试图让我编写的拦截器正常工作,但由于某种原因,当我请求组件时,它似乎没有实例化拦截器。 我正在做这样的事情(如果这不能完全编译,请原谅我,但你应该明白这个想法):
container.Register(
Component.For<MyInterceptor>().LifeStyle.Transient,
AllTypes.Pick().FromAssembly(...).If(t => typeof(IView).IsAssignableFrom(t)).
Configure(c => c.LifeStyle.Is(LifestyleType.Transient).Named(...).
Interceptors(new InterceptorReference(typeof(MyInterceptor)).
WithService.FromInterface(typeof(IView)));
我已经在拦截器的构造函数中放置了断点,但它似乎根本没有实例化它。
过去我使用 XML 配置注册了我的拦截器,但我热衷于使用流畅的界面。
任何帮助将不胜感激!
I'm trying to get an interceptor I've written to work, but for some reason it doesn't seem to be instantiating the interceptor when I request my components. I'm doing something like this (forgive me if this doesn't quite compile, but you should get the idea):
container.Register(
Component.For<MyInterceptor>().LifeStyle.Transient,
AllTypes.Pick().FromAssembly(...).If(t => typeof(IView).IsAssignableFrom(t)).
Configure(c => c.LifeStyle.Is(LifestyleType.Transient).Named(...).
Interceptors(new InterceptorReference(typeof(MyInterceptor)).
WithService.FromInterface(typeof(IView)));
I've put breakpoints in the constructor for the Interceptor and it doesn't seem to be instantiating it at all.
In the past I've registered my interceptors using the XML configuration, but I'm keen to use the fluent interface.
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您滥用了
WithService.FromInterface
。 文档说:您还缺少
InterceptorGroup Anywhere
。这是一个工作示例,我对您的示例进行了尽可能少的更改以使其工作:
I think you're misusing
WithService.FromInterface
. The docs say:You're also missing the
InterceptorGroup Anywhere
.Here's a working sample, I changed it as little as possible from your sample to make it work: