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() {
         install(ThrowingProviderBinder.forModule(this));
       }
    
       @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);