JMSDiExtraBundle
JMSDiExtraBundle copied to clipboard
Injection in services ?
hi thank for this bundle. i'm trying to inject in service same services.
use Ecommerce\EcommerceCoreBundle\Model\CartDetail;
use JMS\DiExtraBundle\Annotation as DI;
class CartService
{
public $em;
public $session;
/**
* @var CartDetail
*/
private $cartDetail;
/**
* @DI\InjectParams({
* "em" = @DI\Inject("doctrine.orm.entity_manager"),
* "session" = @DI\Inject("session")
* })
*/
/**
* @param CartDetail $cartDetail
* @param $em
* @param $session
*/
public function __construct($em, $session)
{
$this->em = $em;
$this->session = $session;
}
Declaration:
services:
app.cart.services:
class: Ecommerce\EcommerceCoreBundle\Controller\Services\CartService
arguments:
# - "@router"
# - "@doctrine.orm.entity_manager"
# - "@member.user_service"
CONFIG.YML
jms_di_extra:
locations:
all_bundles: false
bundles: [ArticleBundle, EcommerceCoreBundle]
directories: ["%kernel.root_dir%/../src"]
automatic_controller_injections:
properties:
request: "@request"
router: "@router"
but i get alwase null
where i get wrong ?
thank any help
for the injection to work you need to have only one docblock:
/**
* @DI\InjectParams({
* "em" = @DI\Inject("doctrine.orm.entity_manager"),
* "session" = @DI\Inject("session")
* })
* @param $em
* @param $session
*/