tags:

views:

105

answers:

1

Hi All

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)

+3  A: 

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.

gpampara
This is exactly what I need.
Roman