dongliechuich10319
dongliechuich10319
2017-09-25 08:43

Symfony DIC - 重新初始化实例

已采纳

I am using Symfony DIC using yaml file for example

services:
    mailer:
        class:     Mailer
        arguments: ['%mailer.transport%']
    newsletter_manager:
        class:     NewsletterManager
        calls:
            - [setMailer, ['@mailer']]

And then i am fetching the object by using

->getContainer()
->get('newsletter_manager');

How can i create a new instance of the object each time i am getting it? I want to reinitialize it for every use.

Thanks

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doutan5798 doutan5798 4年前

    From symfony docs:

    In order to always get a new instance, set the shared setting to false in your service definition:

    services:
        AppBundle\SomeNonSharedService:
            shared: false
    
    点赞 评论 复制链接分享

相关推荐