Wiki

Clone wiki

guice-config / Classes

Custom classes

TestClass.class

#!java
import com.google.inject.Inject;

public class TestClass {

    @Inject
    @Config( Property.TEST_KEY )
    private String injectedValue;

    public String getInjectedValue() {
        return injectedValue;
    } 
}

Property.class

#!java
public enum Property {
    TEST_KEY
}

Config.class

#!java
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.google.inject.BindingAnnotation;

@BindingAnnotation
@Retention( RetentionPolicy.RUNTIME )
@Target( { ElementType.FIELD, ElementType.PARAMETER } )
public @interface Config {
    Property value();
}

ConfigModule.class

#!java
import org.bitbucket.strangerintheq.guiceconfig.GuiceConfigModule;
import java.lang.annotation.Annotation;
import java.util.Properties;

public class ConfigModule extends GuiceConfigModule<Property> {

    public ConfigModule( Properties props ) {
        super( props, Property.values() );
    }

    @Override
    protected Annotation createBindingAnnotation( Property prop ) {
        return new BindingAnnotation( prop );
    }
}

BindingAnnotation.class

#!java

import org.bitbucket.strangerintheq.guiceconfig.BindingAnnotationBase;

class BindingAnnotation extends BindingAnnotationBase<Property> implements Config {

    BindingAnnotation( Property bindingKey ) {
        super( bindingKey, Config.class );
    }
}

◄ UsageHome ►

Updated