目次
コンポーネントが自分自身が登録されているS2Containerに依存している場合は、プロパティインジェクションで
S2Containerインスタンスを取得することができます。S2Containerのコンポーネント名は「container」です。
例として、次のようなサービスクラスを作成します。自動バインディングによりプロパティインジェクションによってS2ContainerインスタンスがDIされます。
module Example
class Service
s2comp
def initialize
@container = :container
end
attr_reader :container
end
end
実行スクリプトは次のように作成します。
require 's2container' require 'example' service = s2app.get(Example::Service) p service.container.class.name
![]() | NOTE |
|---|---|
|
このExampleは example/example12 にあります。 |
| © Copyright The Seasar Foundation and the others 2008-2009, all rights reserved. |