Look at guice-persist or onami-persist. They deal wir DB connections which also 
need to be closed after it has been used.
To do so they both use the concept of UnitOfWork. The application is then 
responsible for spanning the UnitOfWork around the code which needs the 
resource.

Am 30. April 2016 01:40:44 MESZ, schrieb Andree Surya <[email protected]>:
>Hi there,
>
>I have the following Guice binding in my application.
>
>bind(Reader.class)
>    .annotatedWith(DictionarySourceReader.class)
>    .toProvider(DictionarySourceProvider.class);
>
>DictionarySourceProvider will provide a FileReader object, which will
>be injected to a DictionarySourceParser.
>
>
>public class DictionarySourceParser {
>
>    private Reader sourceReader;
>
>    @Inject
>  DictionarySourceParser(@DictionarySourceReader Reader sourceReader) {
>        this.sourceReader = sourceReader;
>    }
>
>    public List<DictionaryEntry> parse() {
>
>        // Parsing entries from the reader ....
>
>        return entries;
>    }
>}
>
>I have two questions:
>
>
>1. When DictionarySourceParser is done with the Reader, who has the
>responsibility to close the reader? Should the parser be responsible?
>2. Is it a commonplace to inject a resource that should be cleaned-up
>after (e.g. Closable)? In general, who has the responsibility for the
>clean-up?
>
>Cheers,
>Andree
>
>-- 
>You received this message because you are subscribed to the Google
>Groups "google-guice" group.
>To unsubscribe from this group and stop receiving emails from it, send
>an email to [email protected].
>To post to this group, send email to [email protected].
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/bc764248-c00d-47c2-8207-2fd45087b352%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/D554D6B0-87B5-4BDF-A61C-0F5C03B0742E%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to