V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
lml12377
V2EX  ›  问与答

Phalcon 为什么每个组件都要实现一次 InjectionAwareInterface ?

  •  
  •   lml12377 · Aug 16, 2016 · 1375 views
    This topic created in 3541 days ago, the information mentioned may be changed or developed.

    看了下源码, InjectionAwareInterface 里面主要是为了设置和获得容器句柄: setDI()/getDI()

    翻了下 Request/Response ,发现都是自己实现了 InjectionAwareInterface ,这样每个 Service 都可以自己拿到 $di 句柄,自己去拿之前注册进去的依赖。

    想问下,为何不弄个基类,比如 Component ,把 setDI()/getDI() 写到基类里面,或者直接用 construct 代替 set ,看到 Application 基类里面是这么搞的,那为啥还要 interface 那种实现?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5466 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 05:56 · PVG 13:56 · LAX 22:56 · JFK 01:56
    ♥ Do have faith in what you're doing.