Last active
August 29, 2015 14:14
-
-
Save aasokan/80f95922764fb73159c3 to your computer and use it in GitHub Desktop.
Checked Provider guice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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