Shouldn't you just move the initialization logic into the provider? assuming it isn't marked @EagerSingleton (or @Singleton and you are in Stage.PRODUCTION), guice will only invoke your provider if someone is actually injecting it
On Thu, Feb 4, 2016 at 11:28 AM Sam Berlin <[email protected]> wrote: > You should be able to use the ProvisionListener API to do this. > > sam > > On Thu, Feb 4, 2016, 2:13 PM Kevin Burton <[email protected]> wrote: > >> I have a component that loads a fairly large corpus off disk to perform >> language classification. >> >> We have a few actually. >> >> What I'd like to do is ONLY do initialization if I was actually injected. >> >> I DO NOT want to do initialization it wasn't injected and isn't going to >> be used. This should dramatically speed up our unit tests (we have >> thousands of them and a few seconds here and there adds up) >> >> I can't do lazy init because then my code has additional and >> non-deterministic latency when first used. Additionally, it now has to >> handle exceptions ... >> >> What I'd really like is an API so that it can detect that it was injected >> and then only do initialization now that its going to be used by some API. >> >> Is this possible? >> >> -- >> 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/a30b61dd-a488-41b0-89de-467285032abd%40googlegroups.com >> <https://groups.google.com/d/msgid/google-guice/a30b61dd-a488-41b0-89de-467285032abd%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> 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/CAJEBNUeJ%3DCtMZx-XsfTEL0CgBggbJbyPWdKS2DS2kK%3DZ2WPxeQ%40mail.gmail.com > <https://groups.google.com/d/msgid/google-guice/CAJEBNUeJ%3DCtMZx-XsfTEL0CgBggbJbyPWdKS2DS2kK%3DZ2WPxeQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > 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/CAO9V1M%2B8jonTHd7neTn4GsKXBU%3D9uM6cEBA%3Da_g1ciu5POyq%3DA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
