我有一个控制器类。
此类需要不同的枚举值,具体取决于注入的位置。我不想为控制器创建子类。
我怎样才能做到这一点?
例子:
class FirstItem {
//some of these have an injected controller which needs the enum value 'FIRST'
@Inject
@FirstSubItems //Custom annotation for multibinding
Set<Item> subItems;
}
class SecondItem {
//some of these have an injected controller which needs the enum value 'SECOND'
@Inject
@SecondSubItems //Custom annotation for multibinding
Set<Item> subItems;
}
class Controller {
@Inject
MyEnum enumValue;
}
这可以优雅地完成吗?我将如何配置模块?
该模块目前看起来像这样:
Multibinder<Item> toolsSectionOne = Multibinder.newSetBinder(binder, Item.class, FirstSubItems.class);
toolsSectionOne.addBinding().to(Item1.class);
toolsSectionOne.addBinding().to(Item2.class);
Multibinder<Item> toolsSectionTwo = Multibinder.newSetBinder(binder, Item.class, SecondSubItems.class);
toolsSectionTwo.addBinding().to(Item1.class);
toolsSectionTwo.addBinding().to(Item2.class);