dependency injection บน Python

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

ผมลองหาดูจาก wikipedia ก็เจอ PyContainer ที่ออก version ล่าสุดคือ 0.4 เมื่อปี 2004. ดูเหมือนไม่ค่อนมีคนสนใจทำ DI (IOC) บน Python เท่าไหร่? อาจจะเป็นเพราะว่า Python อาจจะมีท่าอะไรที่ support DI อยู่แล้ว (แต่ผมไม่รู้)?

PyContainer ออกแนวๆ Spring. อยากได้อะไรแบบ Guice.

ฝั่ง ruby ก็เป็นแบบนี้เหมือนกัน
น่าสงสัยเหมือนกันนะว่าทำไม?
DI ที่ดูเหมือนเป็นหัวใจในฝั่ง java, แต่สำหรับภาษาอื่นแล้ว ดูจะ meaningless.

แต่บทความนี้ น่าสนใจดี
เขาพูดเรื่องแทนที่จะใช้ DI ก็ใช้ switch context แทน
http://relevancellc.com/2007/5/23/recontexting-and-hygienic-code.html

sugree's picture

ว่ากันว่า IoC สำหรับภาษาอย่าง C/C++/Java มันท้าทายมาก แต่สำหรับภาษาอย่าง Python/Ruby มันง่ายซะจนเขียนได้ง่ายๆ ถ้าอยากได้แบบ Guice ก็เขียนเองโลด ใช้ decorator เหมือนกัน

veer's picture

ขอบคุณมากครับ :-).
---
http://openil.wordpress.com/

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น