Skip to content

Instantly share code, notes, and snippets.

@aasokan
Last active August 29, 2015 14:14
Show Gist options
  • Save aasokan/80f95922764fb73159c3 to your computer and use it in GitHub Desktop.
Save aasokan/80f95922764fb73159c3 to your computer and use it in GitHub Desktop.
Checked Provider guice
// CheckedProvider is an interface, which is a part of extension guice-throwingproviders.
public interface CheckedProvider<T> {
T get() throws Exception;
}
// Injection
@Inject
private ExcelCheckedProvider<FlightSupplier> excelCheckedProvider;
// Binding
ThrowingProviderBinder.create(binder()).
bind(ExcelCheckedProvider.class, FlightSupplier.class).
to(ExcelCheckedSupplierProvider.class);
// Usage
try
{
excelCheckedProvider.get().getResults();
} catch (NoExcelAvailableException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment