Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More cleanup with Guice/Injector

  • Loading branch information...
commit b0905ed2031662051d24af33dde428fcb4e8119d 1 parent a1f846f
@jfarcand jfarcand authored
View
14 restsimple-jaxrs/src/main/java/org/sonatype/restsimple/jaxrs/guice/RestSimpleJaxrsModule.java
@@ -90,26 +90,18 @@ public RestSimpleJaxrsModule( Injector parent, Map<String, String> jaxrsProperti
*/
@Override
protected final void configureServlets() {
- boolean bindServiceDefinition = true;
if (parent == null) {
injector = Guice.createInjector();
- } else if (parent.getBinding( ServiceDefinition.class ) == null) {
- injector = parent.createChildInjector();
- bindServiceDefinition = false;
} else {
injector = parent;
}
NegotiationTokenGenerator token = injector.getInstance( NegotiationTokenGenerator.class );
- if (parent == null || bindServiceDefinition || parent.getBinding(NegotiationTokenGenerator.class ) == null) {
- bind(NegotiationTokenGenerator.class).toInstance( token );
- }
+ bind(NegotiationTokenGenerator.class).toInstance( token );
ServiceHandlerMapper mapper = injector().getInstance( ServiceHandlerMapper.class );
- if (parent == null || bindServiceDefinition || parent.getBinding(ServiceHandlerMapper.class ) == null) {
- bind( ServiceHandlerMapper.class ).toInstance( mapper );
- }
-
+ bind( ServiceHandlerMapper.class ).toInstance( mapper );
+
sdSet.addAll( defineServices( injector ) );
ServiceDefinitionGenerator generator = new JAXRSServiceDefinitionGenerator( new ResourceModuleConfig<Module>() {
View
15 ...simple-sitebricks/src/main/java/org/sonatype/restsimple/sitebricks/guice/RestSimpleSitebricksModule.java
@@ -81,9 +81,6 @@ protected final void configureServlets() {
boolean bindServiceDefinition = true;
if (parent == null) {
injector = Guice.createInjector();
- } else if (parent.getBinding( ServiceDefinition.class ) == null) {
- injector = parent.createChildInjector();
- bindServiceDefinition = false;
} else {
injector = parent;
}
@@ -113,14 +110,10 @@ public void install(Module module) {
});
NegotiationTokenGenerator token = injector.getInstance( NegotiationTokenGenerator.class );
- if (parent == null || bindServiceDefinition || parent.getBinding(NegotiationTokenGenerator.class ) == null) {
- bind(NegotiationTokenGenerator.class).toInstance( token );
- }
-
- ServiceHandlerMapper mapper = injector().getInstance( ServiceHandlerMapper.class );
- if (parent == null || bindServiceDefinition || parent.getBinding(ServiceHandlerMapper.class ) == null) {
- bind( ServiceHandlerMapper.class ).toInstance( mapper );
- }
+ bind(NegotiationTokenGenerator.class).toInstance( token );
+
+ ServiceHandlerMapper mapper = injector.getInstance( ServiceHandlerMapper.class );
+ bind( ServiceHandlerMapper.class ).toInstance( mapper );
if (sdSet != null && sdSet.size() > 0) {
for (ServiceDefinition sd : sdSet) {
Please sign in to comment.
Something went wrong with that request. Please try again.