title: How can I use google guice DI outside of testNG test classes in a testNG based framework?
body: <p>it is very simple to implement injection of objects into a testNG test class, it is handled mostly for us, however how can I build google guice DI into my framework and use it for classes which are not necessarily tests?</p>
  
  <p>I want to inject using simple dependency injection for dependencies of my Page Object classes, these are nothing really to do with testNG, so how can we get the dependencies initialized for those?</p>
  
  <p>Here is a simple example piece of code I want to replace:</p>
  
  <pre><code>public class HeaderComponent extends AbstractBasePageObject {
      private static final Logger LOG = LoggerFactory.getLogger(HeaderComponent.class);
      private MenuComponent menu = new MenuComponent(getDriver());
  
  
      public HeaderComponent(NgWebDriver ngdriver) {
          super(ngdriver);
      }
  
      public MenuComponent getMenuComponent() {
          return menu;
      }
  }
  </code></pre>
  
  <p>This class is absolutely nothing to do with testNG itself, so how can I initialize everything for the outcome of:</p>
  
  <pre><code>@Inject
  MenuComponent menu
  </code></pre>
  
  <p>Everything I try the menu throws a nullPointerException because I am having trouble having guice somewhat loaded I think.</p>