java Google Guice:带参数的提供者

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4948606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:45:06  来源:igfitidea点击:

Google Guice: Provider with parameters

javadependency-injectionguice

提问by Abidi

I have a constructor that depends on classes A and B. I defined it like this:

我有一个依赖于类 A 和 B 的构造函数。我这样定义它:

@Inject TestClass(A a, B b)

Is there a way in Guice to have one of the constructor parameters injected manually?

Guice 中有没有办法手动注入构造函数参数之一?

Problem is, the object of class Acannot be built as it depends on the user input. I was just wondering if Guice supports a provider that accepts an argument. For example, currently an object can be created by provider.get(), does Guice has one that support provider.get(a)?

问题是,类的对象A无法构建,因为它取决于用户输入。我只是想知道 Guice 是否支持接受参数的提供者。例如,目前一个对象可以由 来创建provider.get(),Guice 有支持provider.get(a)吗?

回答by ColinD

I think what you need is Assisted Inject.

我认为您需要的是辅助注射