douhuan1979 2014-02-05 10:35 采纳率: 100%
浏览 26

Symfony2:在其他服务之间注入服务的更好方法

I've read some post regarding this subject but I'm still wondering if there is a better way to "auto inject" any service. I mean, if I have a namespace called person services (which includes personalDataService, relativesDataService, etc) it'd be great if I could do something like this:

services:
    Person.personalData:
        class:        Main\UserBundle\Services\PersonalDataService
        arguments: [Person.*]

    Person.relativesData:
        class:        Main\UserBundle\Services\RelativesataService
        arguments: [Person.*]

I know that is possible to follow this post but I'm looking for other "efficient" way

  • 写回答

1条回答 默认 最新

  • dougutuo9879 2014-02-05 10:59
    关注

    There is not better way. The best way is the way that is described in your own post...

    Why is that?

    You don't want to inject unneeded services because if you start injecting services that you won't use then your destroying your own app with clutter and it will more or less slow down. So basicly using the way as described in the post above is the best way because you will be wondering for yourself again what do I really need and only put in the neccesary stuff... If that means later on you have to change your config and service constructor because you need an extra service injected so it is.

    I hope this answers your question...

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?