title: How to Use Object Manager in Symfony3
body: <p>Error</p>
  
  <pre><code>      Catchable Fatal Error: Argument 2 passed to Acme\StoreBundle\Security\TokenAuthenticator::__construct() must be an instance of Doctrine\Common\EventManager, instance of Doctrine\Bundle\MongoDBBundle\ManagerRegistry given, called in D:\xamppNew\htdocs\mtl_project\var\cache\dev\appDevDebugProjectContainer.php on line 6178 and defined
  </code></pre>
  
  <p>TokenAuthenticator.php </p>
  
  <pre><code>        &lt;?php
  
  
          namespace Acme\StoreBundle\Security;
  
          use Doctrine\Common\EventManager;
          use Doctrine\Common\Persistence\ObjectManager;
          use Doctrine\Common\Persistence\ObjectRepository;
          use Doctrine\MongoDB\Connection;
          use Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo;
          use Doctrine\ODM\MongoDB\Mapping\MappingException;
          use Doctrine\ODM\MongoDB\Hydrator\HydratorFactory;
          use Doctrine\ODM\MongoDB\Proxy\ProxyFactory;
          use Doctrine\ODM\MongoDB\Query\FilterCollection;
          use Doctrine\ODM\MongoDB\Repository\RepositoryFactory;
  
          //use Acme\StoreBundle\Security\TokenAuthenticator;
          use Lexik\Bundle\JWTAuthenticationBundle\Encoder\JWTEncoderInterface;
          use Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor\AuthorizationHeaderTokenExtractor;
          use Symfony\Component\HttpFoundation\Request;
          use Symfony\Component\HttpFoundation\Response;
          use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
          use Symfony\Component\Security\Core\Exception\AuthenticationException;
          use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
          use Symfony\Component\Security\Core\User\UserInterface;
          use Symfony\Component\Security\Core\User\UserProviderInterface;
          use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
  
          class TokenAuthenticator extends AbstractGuardAuthenticator
          {
          /**
          * @var JWTEncoderInterface
          */
          private $jwtEncoder;
          /**
          * @var Doctrine\Common\Persistence\ObjectManager
          */
          protected $om;
          /**
          * @param JWTEncoderInterface $jwtEncoder
          * @param ObjectManager       $om
          */
          public function __construct(JWTEncoderInterface $jwtEncoder, Doctrine\Common\Persistence\ObjectManager $om)
          {
          $this-&gt;jwtEncoder = $jwtEncoder;
          $this-&gt;om = $om;
          }
          /**
          * @inheritdoc
          */
          public function getCredentials(Request $request)
          {
          $extractor = new AuthorizationHeaderTokenExtractor(
          'Bearer',
          'Authorization'
          );
          $token = $extractor-&gt;extract($request);
          if (!$token) {
          return;
          }
          return $token;
          }
          /**
          * @inheritdoc
          */
          public function getUser($credentials, UserProviderInterface $userProvider)
          {
          $data = $this-&gt;jwtEncoder-&gt;decode($credentials);
          if ($data === false) {
          throw new CustomUserMessageAuthenticationException('Invalid Token');
          }
          $username = $data['username'];
          return $this-&gt;om
          -&gt;getRepository('UserBundle:User')
          -&gt;findOneBy(['username' =&gt; $username]);
          }
          /**
          * @inheritdoc
          */
          public function checkCredentials($credentials, UserInterface $user)
          {
          return true;
          }
          /**
          * @inheritdoc
          */
          public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
          {
          }
          /**
          * @inheritdoc
          */
          public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
          {
          }
          /**
          * @inheritdoc
          */
          public function supportsRememberMe()
          {
          return false;
          }
          /**
          * @inheritdoc
          */
          public function start(Request $request, AuthenticationException $authException = null)
          {
          return new Response('Token is missing!', Response::HTTP_UNAUTHORIZED);
          }
          }
  </code></pre>
  
  <p>Refrence</p>
  
  <p><a href="https://stackoverflow.com/questions/10285783/difference-between-objectmanager-and-entitymanager-in-symfony2">Difference between ObjectManager and EntityManager in Symfony2?</a></p>
  
  <p><a href="https://github.com/doctrine/mongodb-odm/blob/785c5039d51923d22902fa1249d1e3dd64018838/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L44" rel="nofollow noreferrer">https://github.com/doctrine/mongodb-odm/blob/785c5039d51923d22902fa1249d1e3dd64018838/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L44</a></p>
  
  <ul>
  <li><p>im new in symfonymongodb bundle</p></li>
  <li><p>can anyone suggest how can i use object manager in contructor as symfony is throwing errors.</p></li>
  </ul>