config-inject

Configuration system using Guice and config-magic

License

License

Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

com.palominolabs.config
ArtifactId

ArtifactId

config-inject
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

config-inject
Configuration system using Guice and config-magic
Project URL

Project URL

https://github.com/palominolabs/config-inject
Source Code Management

Source Code Management

https://github.com/palominolabs/config-inject

Download config-inject

How to add to project

<!-- https://jarcasting.com/artifacts/com.palominolabs.config/config-inject/ -->
<dependency>
    <groupId>com.palominolabs.config</groupId>
    <artifactId>config-inject</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.palominolabs.config/config-inject/
implementation 'com.palominolabs.config:config-inject:1.0.0'
// https://jarcasting.com/artifacts/com.palominolabs.config/config-inject/
implementation ("com.palominolabs.config:config-inject:1.0.0")
'com.palominolabs.config:config-inject:jar:1.0.0'
<dependency org="com.palominolabs.config" name="config-inject" rev="1.0.0">
  <artifact name="config-inject" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.palominolabs.config', module='config-inject', version='1.0.0')
)
libraryDependencies += "com.palominolabs.config" % "config-inject" % "1.0.0"
[com.palominolabs.config/config-inject "1.0.0"]

Dependencies

compile (6)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.6.6
com.google.code.findbugs : jsr305 jar 2.0.1
commons-configuration : commons-configuration jar 1.8
com.google.guava : guava jar 13.0
com.google.inject : guice jar 3.0
org.skife.config : config-magic jar 0.14

test (3)

Group / Artifact Type Version
junit : junit-dep jar 4.10
org.hamcrest : hamcrest-core jar 1.3
ch.qos.logback : logback-classic jar 1.0.6

Project Modules

There are no modules declared in this project.

config-inject

Build Status Download

config-inject is a library to make it easy to inject configuration data into your classes with Guice and config-magic.

Artifacts are published to Bintray, so use jcenter() in your Gradle dependencies block (or analogous Maven config).

You can stack multiple sources of configuration data.

ConfigModuleBuilder builder = new ConfigModuleBuilder();
// load from a file
builder.addPropertiesFile(new File("/foo/bar"))
        // or input stream
       .addPropertiesInputStream(getClass().getResourceAsStream("/some/other/config")
       // or system properties, or any other commons-configuration Configuration
       .addConfiguration(new SystemConfiguration());

Once you've set up your config data, use config-magic to access it. Define a config interface or abstract class:

public interface SomeAppConfig {
    @Config("com.app.service.host")
    @Default("localhost")
    String getHost();

    @Config("com.app.service.port")
    @Default("1234")
    int getPort();
}

Bind up the necessary stuff in Guice:

Guice.createInjector(builder.build(), new AbstractModule() {
        @Override
        protected void configure() {
            ConfigModule.bindConfigBean(binder(), SomeAppConfig.class);
        }
});

Now you can inject the config interface into your classes as needed.

class SomeClass {
    @Inject
    SomeClass(SomeAppConfig config) {
        // do something configurable
    }
}
com.palominolabs.config

Palomino Labs

Versions

Version
1.0.0