2.2. Registration and getting of a component

A component is registered by the s2component method. Getting of a component is performed by the get method of S2ApplicationContext class. The s2app method is the shortcut to S2ApplicationContext class.

require 's2container'

class Action

action = s2app.get(Action)
action = s2app[Action]       # [] method is also available.
action = Action.instance     # s2app.get(Action) is called in the instance method (class method).

In the above example, since Action class is registered as a component, Action class is specified as an argument of the get method of S2ApplicationContext class.


This Example is located at "example/quickstart/quickstart1".

© Copyright The Seasar Foundation and the others 2008-2009, all rights reserved.