lml12377
V2EX  ›  问与答

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

  •  
  •   lml12377 · Aug 16, 2016 · 1467 views
    This topic created in 3597 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   ·   910 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:47 · PVG 05:47 · LAX 14:47 · JFK 17:47
    ♥ Do have faith in what you're doing.