Allow to override the Image and Security extension bindings

Some providers, such as Azure ARM, might need additional
resources present in order to be able to use the extension.
This change allows to override its binding (Guice 4 by default does not
allow to override provider bindings, so we need to define them as final
ones and provide an alternate method for subclasses that need to
override the binding).
This commit is contained in:
Ignasi Barrera 2016-05-21 00:30:31 +02:00
parent b7ed4f34ab
commit d05af2246b
1 changed files with 10 additions and 4 deletions

View File

@ -304,16 +304,22 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Provides
@Singleton
public final Optional<ImageExtension> guiceProvideImageExtension(Injector i) {
Binding<ImageExtension> binding = i.getExistingBinding(Key.get(ImageExtension.class));
return binding == null ? Optional.<ImageExtension> absent() : Optional.of(binding.getProvider().get());
return provideImageExtension(i);
}
@Provides
@Singleton
protected final Optional<SecurityGroupExtension> guiceProvideSecurityGroupExtension(Injector i) {
return provideSecurityGroupExtension(i);
}
protected Optional<ImageExtension> provideImageExtension(Injector i) {
Binding<ImageExtension> binding = i.getExistingBinding(Key.get(ImageExtension.class));
return binding == null ? Optional.<ImageExtension> absent() : Optional.of(binding.getProvider().get());
}
protected Optional<SecurityGroupExtension> provideSecurityGroupExtension(Injector i) {
Binding<SecurityGroupExtension> binding = i.getExistingBinding(Key.get(SecurityGroupExtension.class));
return binding == null ? Optional.<SecurityGroupExtension> absent() : Optional.of(binding.getProvider().get());
}
}