Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Commit

Permalink
Bind application config with all contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-shpak committed Feb 12, 2018
1 parent d158598 commit 83f6f57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
hk2bundleVersion=0.6.3-SNAPSHOT
hk2bundleVersion=0.6.4-SNAPSHOT
dropwizardVersion=1.2.2
junitVersion=4.12
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.glassfish.hk2.api.ServiceLocator;
import org.jvnet.hk2.annotations.Contract;

import javax.inject.Inject;
import java.lang.reflect.Type;
import java.util.Set;

import static org.glassfish.hk2.utilities.ServiceLocatorUtilities.addOneConstant;
import static org.glassfish.hk2.utilities.reflection.ReflectionHelper.getAdvertisedTypesFromObject;

/**
* Configured bundle used to obtain and bind configuration instance into DI container.
Expand All @@ -25,7 +29,10 @@ public void initialize(Bootstrap<?> bootstrap) {

@Override
public void run(Configuration configuration, Environment environment) {
addOneConstant(serviceLocator, configuration, null,
configuration.getClass(), Configuration.class);
Set<Type> contracts = getAdvertisedTypesFromObject(configuration, Contract.class);
contracts.add(configuration.getClass());
contracts.add(Configuration.class);

addOneConstant(serviceLocator, configuration, null, contracts.toArray(new Type[0]));
}
}

0 comments on commit 83f6f57

Please sign in to comment.