title: Dependency Injection - Cucumber Pico Container
body: <p>I am having difficulty understanding and utilizing dependency injection in my situation. I want to use Pico-container (<a href="https://cucumber.io/blog/2015/07/08/polymorphic-step-definitions" rel="nofollow noreferrer">https://cucumber.io/blog/2015/07/08/polymorphic-step-definitions</a>).</p>
  
  <p>This is my situation...I currently have one step definition class that contains all my selenium, and which is getting way too big:</p>
  
  <pre><code>public class StepDefinitions{
      public static WebDriver driver; // a driver is returned here from a static Driver Factory Class
      LoginPage loginPage = new LoginPage(driver); //Page Object Model(s)
  
      @Before("setup")
      @After //screen snapshot
      @After("destroy")
      @Given //many methods with this tag
      @When  //many methods with this tag
      @Then  //many methods with this tag
  }
  </code></pre>
  
  <p>Now I want to potentially have one class that contains my driver, POMs, and Hooks:</p>
  
  <pre><code>public static WebDriver driver; //driver is returned from a static Driver Factory Class
  LoginPage loginPage = new LoginPage(driver); //Page Object Model(s)
  
   @Before("setup")
   @After
   @After("destroy")
  </code></pre>
  
  <p>Another class that contains my <code>@Given</code>, one class that contains my <code>@When</code>, and one class that contains my <code>@Then</code></p>
  
  <p>I then need to connect everything up right, so <strong>all classes</strong> can utilize the driver, hooks, and POMs. Cucumber does not support inheritance, so interfaces or Dependency Injection (Pico Container) is the way to go. I do not know how to do this, and I have studied online, I just cannot wrap my poor brain around it all.</p>