com.google.inject.throwingproviders

Class ThrowingProviderBinder



  • public class ThrowingProviderBinder
    extends Object

    Builds a binding for a CheckedProvider.

    You can use a fluent API and custom providers:

    ThrowingProviderBinder.create(binder())
        .bind(RemoteProvider.class, Customer.class)
        .to(RemoteCustomerProvider.class)
        .in(RequestScope.class);
     
    or, you can use throwing provider methods:
    class MyModule extends AbstractModule {
       configure() {
         ThrowingProviderBinder.install(this, binder());
       }
       
        @CheckedProvides(RemoteProvider.class)
        @RequestScope
       Customer provideCustomer(FlakyCustomerCreator creator) throws RemoteException {
         return creator.getCustomerOrThrow();
       }
     }
     
    You also can declare that a CheckedProvider construct a particular class whose constructor throws an exception:
    ThrowingProviderBinder.create(binder())
        .bind(RemoteProvider.class, Customer.class)
        .providing(CustomerImpl.class)
        .in(RequestScope.class);
     

    Author:
    jmourits@google.com (Jerome Mourits), jessewilson@google.com (Jesse Wilson), sameb@google.com (Sam Berlin)

Copyright © 2006-2016 Google, Inc.. All Rights Reserved.