Class ThrowingProviderBinder
- java.lang.Object
-
- com.google.inject.throwingproviders.ThrowingProviderBinder
-
public class ThrowingProviderBinder extends Object
Builds a binding for aCheckedProvider
.You can use a fluent API and custom providers:
or, you can use throwing provider methods:ThrowingProviderBinder.create(binder()) .bind(RemoteProvider.class, Customer.class) .to(RemoteCustomerProvider.class) .in(RequestScope.class);
You also can declare that a CheckedProvider construct a particular class whose constructor throws an exception:class MyModule extends AbstractModule { configure() { install(ThrowingProviderBinder.forModule(this)); } @CheckedProvides(RemoteProvider.class) @RequestScope Customer provideCustomer(FlakyCustomerCreator creator) throws RemoteException { return creator.getCustomerOrThrow(); } }
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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ThrowingProviderBinder.SecondaryBinder<P extends CheckedProvider,T>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <P extends CheckedProvider,T>
ThrowingProviderBinder.SecondaryBinder<P,T>bind(Class<P> interfaceType, com.google.inject.TypeLiteral<T> typeLiteral)
<P extends CheckedProvider,T>
ThrowingProviderBinder.SecondaryBinder<P,T>bind(Class<P> interfaceType, Class<T> clazz)
<P extends CheckedProvider>
ThrowingProviderBinder.SecondaryBinder<P,?>bind(Class<P> interfaceType, Type clazz)
Deprecated.Usebind(Class, Class)
orbind(Class, TypeLiteral)
instead.static ThrowingProviderBinder
create(com.google.inject.Binder binder)
static com.google.inject.Module
forModule(com.google.inject.Module module)
Returns a module that installs @CheckedProvides
methods.
-
-
-
Method Detail
-
create
public static ThrowingProviderBinder create(com.google.inject.Binder binder)
-
forModule
public static com.google.inject.Module forModule(com.google.inject.Module module)
Returns a module that installs @CheckedProvides
methods.- Since:
- 3.0
-
bind
@Deprecated public <P extends CheckedProvider> ThrowingProviderBinder.SecondaryBinder<P,?> bind(Class<P> interfaceType, Type clazz)
Deprecated.Usebind(Class, Class)
orbind(Class, TypeLiteral)
instead.
-
bind
public <P extends CheckedProvider,T> ThrowingProviderBinder.SecondaryBinder<P,T> bind(Class<P> interfaceType, Class<T> clazz)
- Since:
- 4.0
-
bind
public <P extends CheckedProvider,T> ThrowingProviderBinder.SecondaryBinder<P,T> bind(Class<P> interfaceType, com.google.inject.TypeLiteral<T> typeLiteral)
- Since:
- 4.0
-
-