gpslab / geoip2

A Symfony Bundle for the Maxmind GeoIP2 API
https://www.maxmind.com/
MIT License
54 stars 12 forks source link

how to inject service in symfony 4? #16

Closed newbie78 closed 4 years ago

newbie78 commented 4 years ago

Hi!

I need to inject the service into the controller method like this:

namespace App\Controller;

use GeoIp2\Database\Reader;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class ApiController extends AbstractController
{

  public function someAction(Reader $reader)
  {
    dd($reader);
  }
}

but i'm have this error:

"Cannot autowire argument $reader of \"App\\Controller\\ApiController::someAction()\": it references class \"GeoIp2\\Database\\Reader\" but no such service exists. You should maybe alias this class to the existing \"geoip2.reader\" service."

is it possible to do it somehow?

thanx

peter-gribanov commented 4 years ago

You can declare alias for geoip2.reader service

services:
    GeoIp2\Database\Reader:
        alias: 'geoip2.reader'
        public: true
newbie78 commented 4 years ago

ow. thank you very mutch!