lml12377
V2EX  ›  问与答

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

  •  
  •   lml12377 · Aug 16, 2016 · 1412 views
    This topic created in 3563 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   ·   4194 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 10:10 · PVG 18:10 · LAX 03:10 · JFK 06:10
    ♥ Do have faith in what you're doing.