Friday, October 20, 2006

IOC in Tapestry 5

ใน Tapestry 5 นี้
Howard (คนเขียน) เขาจะ implement IOC ขึ้นมาเอง
(เดิมใช้ Hivemind อยู่, ถ้าจะท้าวความให้ลึกอีกหน่อย
Hivemind เกิดขึ้นเพราะต้องการให้เป็น infrastructure ของ Tapestry)
ประเด็นก็คือ เขาไม่มีเวลาพอที่ maintain Hivemind ในรูป Generic IOC container
เพราะต้องการที่จะ customize IOC สำหรับ Tapestry โดยเฉพาะ

แนวของ IOC ตัวใหม่นี้ จะลดการใช้ XML ลง
ลองดูตัวอย่างการ inject แบบนี้ดู น่าสนใจดี
public static Indexer buildIndexer(
@InjectService("JobScheduler") JobScheduler scheduler,
@InjectService("FileSystem") FileSystem fileSystem)
{
IndexerImpl indexer = new IndexerImpl(fileSystem);

scheduler.scheduleDailyJob(indexer);

return indexer;
}


แน่นอน ข้างบนนี้เป็นทางเลือกแบบหนึ่ง
แบบที่คนจำนวนหนึ่งชอบ ก็คือ automatic wire โดยไม่ต้อง config เลย
ก็มีเหมือนกัน

Related link from Roti

2 comments:

Prach Pongpanich said...

พี่ป๊อกในไทยเขาใช้ ruby กันบ้างหรือยังครับ

PPhetra said...

เริ่มเห็นคนใช้กันพอสมควรนะ
อย่างที่เป็น public ใหญ่ๆ ก็
http://gotoknow.org/