Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
More cleanup with Guice/Injector
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Jun 15, 2011
1 parent a1f846f commit b0905ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b0905ed

Please sign in to comment.