title: Real benefits of Java EE CDI
body: <p>I'm new to Java EE and I'm wondering whats the real benefits of using CDI (@Named, @Inject). Of course I was asking the google. But I always got general answers like "loose coupling" and "better to test". But I think to get loose coupling no framework is needed.</p>
  
  <p>In my little project I use three classes</p>
  
  <pre><code>public interface UserIf
  {
      ...
  }
  
  @Named
  public class User implements UserIf
  {
       ...
  }
  
  public class Main
  {
      @Inject
      UserIf user;
  }
  </code></pre>
  
  <p>Now I can easily inject another Implementation of UserIf. But I also could do it with</p>
  
  <pre><code>public class Main
  {
      UserIf user = new User();
  }
  </code></pre>
  
  <p>This architecture is easy to change too. Just write another implementation of UserIf and change</p>
  
  <pre><code>UserIf user = new User();
  </code></pre>
  
  <p>to</p>
  
  <pre><code>UserIf user = new AnotherUserImpl();
  </code></pre>
  
  <p>I don't see a benefit of using CDI here. When I think about a bigger EAR project consisting of some EJBs and WARs, maybe it's easyer to reuse some modules (EJBs, WARs) if they are loose coupled. But as far as I know, it is not possible to use CDI if the classes are not in the same jar/war . So what would be a real setup where you get real benefits of using CDI?</p>
  
  <p>Greetings Helmsen</p>