Java Code Examples for com.google.inject.Binder#addError()

The following examples show how to use com.google.inject.Binder#addError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackupModule.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
protected void setup(Binder binder)
{
    configBinder(binder).bindConfig(BackupConfig.class);

    String provider = buildConfigObject(BackupConfig.class).getProvider();
    if (provider == null) {
        binder.bind(BackupStore.class).toProvider(Providers.of(null));
    }
    else {
        Module module = providers.get(provider);
        if (module == null) {
            binder.addError("Unknown backup provider: %s", provider);
        }
        else if (module instanceof ConfigurationAwareModule) {
            install(module);
        }
        else {
            binder.install(module);
        }
    }
    binder.bind(BackupService.class).to(BackupServiceManager.class).in(Scopes.SINGLETON);
}
 
Example 2
Source File: InjectableMethod.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public Module bindingModule() {
    return new KeyedManifest.Impl(method) {
        @Override
        public void configure() {
            final Binder binder = binder().withSource(method);
            if(!hasReturnValue()) {
                binder.addError("Cannot bind this method as a provider because it does not return a value");
                return;
            }

            install(InjectableMethod.this);

            final ScopedBindingBuilder builder = binder.bind(providedKey).toProvider(asProvider());
            if(scope != null) builder.in(scope);
        }
    };
}