【发布时间】:2023-04-04 11:35:01
【问题描述】:
我目前有一个使用以下绑定的Module impl:
binder.bindInterceptor(Matchers.any(), Matchers.any(),
new WidgetInterceptor());
我希望能够以编程方式打开/关闭此功能,这就是我精心设计的:
private boolean widgetInterceptionEnabled = true;
public void configure(Binder binder) {
Matcher<Object> matcher = null;
if(widgetInterceptionEnabled)
matcher = Matchers.any();
else
matcher = Matchers.not(Matchers.any());
binder.bindInterceptor(Matchers.any(), matcher,
new WidgetInterceptor());
}
这是告诉 Guice 不 匹配任何东西的正确方法吗?还是我使用的 API 有误?
提前致谢!
【问题讨论】:
标签: java dependency-injection aop guice