I was wondering If I can check on the Injector if an instance of some 
class/interface was already or 
have a method that does only return the instance if it was already created.

Why I need this:
In the shutdown of my integration tests I clean up all instances in the 
Service that I am testing.
In most of the tests however some dependencies (TimeoutManager)  are never 
instaniated but will now in the shutdown code only to destroy them right 
afterwards, this takes some time and causes exceptions and a lot of 
confusing output in the test log.


     /**
>
>      * Called by junit after each integration test.
>
>      */
>
>     @After
>
>     public final void afterIntegrationTest() {
>
>         
>
>      if (service != null) {
>>
>>          service.destroy();
>>
>>      }
>>
>>             
>>
>>            // more shutdow
>
    }
>
>
private void tryCloseInstances() {
>
>                // current code 

>         TimeoutManager timeoutManager = 
>> injector.getInstance(TimeoutManager.class);
>
>         AutoCloseables.tryClose(timeoutManager);
>
>
              // what i would like to do               

>           TimeoutManager timeoutManager = 
> injector.getInstanceOnlyIfCreated(TimeoutManager.class);

          AutoCloseables.tryCloseIfNotNull(timeoutManager);

    }
>
>
Br
David L. 

-- 
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 http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/9d7440eb-d99c-4853-a499-f466b85282fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to