title: Entity Manager in Service in Zend Framework 2
body: <p>I have written a custom service for my module. This service provides public static functions which should validate a given token.</p>
  
  <p>Now i want to implement another public static function which checks if an Doctrine-Entity exists or not. For this case i need the object-manager or the service-locator in my service.</p>
  
  <pre class="lang-php prettyprint-override"><code>class ApiService 
  {
      const KEY_LENGTH = 10;
      const USE_NUMBERS = true;
      const USE_CHARS = true;
  
      public static function isValid($apiKey) {
          $isValid = false;
          # more code tbd
          $isValid = self::exists($apiKey);
          return $isValid;
      }
  
      public static function exists($apiKey) {
      # Insert Object-Manager here
  
          $validator = new \DoctrineModule\Validator\ObjectExists(array(
             'object_repository' =&gt; $objectManager-&gt;getRepository('Application\Entity\User'),
             'fields' =&gt; array('email')
          )); 
      }
  }
  </code></pre>
  
  <ol>
  <li><p>Is it "best-practice" to implement my functions as public static and call them as static methods?</p></li>
  <li><p>What is the best practice to inject the object-manager into my <code>doesEntityExist()</code> function?</p></li>
  </ol>