Guice expert question

I am wondering if someone would be such an expert in guice that he even would know how to implement that :

I have an injection annotation ( @ConfParam )with some parameters , like that :

class TestClass {

private final int intValue;

    @Inject
    public TestClass(@ConfParam(section = "test1", key = "1") int intValue{
        this.intValue = intValue;
    }

    public int getIntValue() {
        return intValue;
    }

}

The ConfParam is my custom annotation.

Now , when the injection value is requested , I would like guice to create a dynamic binding, to resolve the value.

For that binding I will need the parameters inside the annotation.

Some example could be , I will have to look in the database in some table where the section is ? and the key is ?.

All the trouble is that the data is not available when the injector is created and could be also be added at runtime.

Ps. I static solution is easy. ( just have a look at the Names class)


Have a look at CustomInjections as a starting point. I have done something similar before that used a parameter to customize a logger further than simply the class name.

链接地址: http://www.djcxy.com/p/94644.html

上一篇: 运行在Guice注入器内部,@Injects不受`new`的尊重

下一篇: 吉斯专家的问题