title: Why has an @ApplicationScoped bean a new instance in the BeforeShutdown phase of my CDI extension ?
body: <p>I would like to make some clean up on a bean when I shutdown a CDI application. For example, I would like to close an IO connection. Of course, here, the bean is marked as @ApplicationScoped. </p>
  
  <p>To manage this I wrote an extension and observe the BeforeShutdown event, and then I select my bean to call a clean up method :</p>
  
  <pre><code>public void beforeShutdown(@Observes BeforeShutdown beforeShutdown) {
      SomeBean obj = CDI.current().select(SomeBean.class).get();
      obj.cleanup();
  }
  </code></pre>
  
  <p>My problem is that I have access to a new instance in this method. Not the instance I got in the whole application.</p>
  
  <p>If you want to see this instance problem, I've made a repo on github to show it : <a href="https://github.com/hasalex/cdi-extension-demo" rel="nofollow">https://github.com/hasalex/cdi-extension-demo</a>.</p>
  
  <p>So I have 2 questions : </p>
  
  <ul>
  <li>Why do I get a new instance ? </li>
  <li>Is there an other way to cleanup my bean at the end of the application ? (in SE and in WildFly environments)</li>
  </ul>