• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

methoparaに触発されてDIコンテナを作成してみました。コンストラクタインジェクションとプロパティインジェクションをサポートしています。

ruby>>
require 'object_injection'

class Juicer
attr_reader :fruit

def initialize fruit
@fruit = fruit
end
end

class Fruit
end

container = ObjectInjection::Container.new
container.add Juicer
container.add Fruit

juicer = container.get :Juicer
p juicer.fruit # => #Fruit:0x00000001059aa0
<<--

詳細は、 http://github.com/takai/object_injection/ をどうぞ。

posted by takai takai on Thu 26 Mar 2009 at 10:55 with 0 comments