title: Convert ZF2 Service Manager to ZF3
body: <p>I have a simple ZF2 application that uses two tables and a service and I'm trying to convert it to run on ZF3.  I can't work out how to update the service manager code.  Here's an example of one of the controllers</p>
  
  <pre><code>    &lt;?php
  namespace LibraryRest\Controller;
  
  use Zend\Mvc\Controller;
  
  use Library\Service\SpydusServiceInterface;
  use Library\Service\SpydusService;
  use Library\Model\BookTitle;
  use Library\Model\BookTitleTable;
  use Library\Model\Author;
  use Library\Model\AuthorTable;
  
  use Zend\Mvc\Controller\AbstractRestfulController;
  use Zend\View\Model\JsonModel;
  
  class SearchRestController extends AbstractRestfulController {
  
      protected $bookTitleTable;
  
      public function getBookTitleTable() {
          if (! $this-&gt;bookTitleTable) {
              $this-&gt;bookTitleTable = $this-&gt;getServiceLocator ()-&gt;get ( 'BookTitleTable' );
          }
          return $this-&gt;bookTitleTable;
      }
  
      protected $authorTable;
  
      public function getAuthorTable() {
          if (! $this-&gt;authorTable) {
              $sm = $this-&gt;getServiceLocator ();
              $this-&gt;authorTable = $sm-&gt;get ( 'AuthorTable' );
          }
          return $this-&gt;authorTable;
      }
  
      protected $spydusService;
  
      public function __construct(SpydusServiceInterface $spydusService) {
          $this-&gt;spydusService = $spydusService;
      }
  
      public function getList($action, $first, $last) {
          if ($action == 'search') {
              return $this-&gt;searchAction ( $first, $last );
          }
      }
  
      public function searchAction() {
          $message = array ();
          $results = array ();
          $first = urldecode ( $this-&gt;params ()-&gt;fromRoute ( 'first' ) );
          $last = urldecode ( $this-&gt;params ()-&gt;fromRoute ( 'last' ) );
          if ($this-&gt;getAuthorTable ()-&gt;getAuthorId ( $first, $last ) === false) {
              $results [0] = array ('count' =&gt; 0, 'message' =&gt; 'This author not found in database', 'first' =&gt; $first, 'last' =&gt; $last, 'title' =&gt; '', 'titleCode' =&gt; '', 'link' =&gt; '', 'authorId' =&gt; '' );
          } else {
              $authorId = $this-&gt;getAuthorTable ()-&gt;getAuthorId ( $first, $last )-&gt;author_id;
              $books = $this-&gt;spydusService-&gt;searchBooks ( $first, $last );
              $count = count ( $books );
              foreach ( $books as $foundTitle ) {
                  if ($foundTitle-&gt;getMessage () == 'Nothing found') {
                      $results [0] = array ('count' =&gt; 0, 'message' =&gt; 'Nothing found by library search', 'first' =&gt; $first, 'last' =&gt; $last, 'title' =&gt; '', 'titleCode' =&gt; '', 'link' =&gt; '', 'authorId' =&gt; '' );
                      break;
                  }
                  $searchBooks = $this-&gt;getBookTitleTable ()-&gt;getId ( $foundTitle-&gt;getTitle (), $authorId );
                  if ($searchBooks-&gt;count () == 0) {
                      $addUrl = "http://newlib.rvw.dyndns.org/library/search/add/" . $authorId . '/' . $foundTitle-&gt;getTitle ();
                      $results [] = array ('count' =&gt; $count, 'message' =&gt; $foundTitle-&gt;getMessage (), 'title' =&gt; $foundTitle-&gt;getTitle (), 'titleCoded' =&gt; $foundTitle-&gt;getTitleCoded (), 'first' =&gt; $foundTitle-&gt;getAuthorFirst (), 'last' =&gt; $foundTitle-&gt;getAuthorLast (), 'link' =&gt; $foundTitle-&gt;getLink (), 'authorId' =&gt; $authorId, 'addUrl' =&gt; $addUrl );
                  }
              }
          }
          if (count ( $results ) == 0) {
              $results [0] = array ('count' =&gt; 0, 'message' =&gt; 'Nothing found by library search', 'first' =&gt; $first, 'last' =&gt; $last, 'title' =&gt; '', 'titleCode' =&gt; '', 'link' =&gt; '', 'authorId' =&gt; '' );
          }
          return new JsonModel ( $results );
      }
  }
  </code></pre>
  
  <p>What code should I use instead of the getServiceLocator() call as this is no longer supported in ZF3?  Elsewhere on Stack Overflow someone had replied to another question and suggested using a createService function but this has been dropped from ZF3 as well.</p>