Chapter 5. MISC

Table of Contents

5.1. Using S2Container in component
5.2. Log setup of S2Container
5.2.1. S2Logger
5.3. Database access using DBI
5.3.1. Component-izing of DBI::DatabaseHandle
5.4. Database access using DBIInterceptor
5.4.1. The outline of DBIInterceptor
5.4.2. Aspect of DBIInterceptor
5.4.3. Setup Bind value by Method argument
5.4.4. Setup Bind value By Method result
5.4.5. Using DBI in Dao
5.4.6. Paging by Paginate class
5.5. S2CGI Web Framework
5.5.1. Setup
5.5.2. Starting of Framework
5.5.3. Seasar::CGI::Page Class
5.5.4. Class Variables
5.5.5. Instance Variables
5.5.6. get/post method
5.5.7. param method
5.5.8. render method
5.5.9. partial method
5.5.10. redirect meshot
5.5.11. validate method
5.5.12. Session management
5.5.13. Dependency Injection
5.5.14. Unit Test
5.5.15. Rack CGI
5.6. Using S2Container with Rails
5.6.1. Environment
5.6.2. Setup
5.6.3. Summary
5.6.4. Dependency Injection

5.1. Using S2Container in component

When the component is dependent on S2Container into which it is registered, S2Container instance can be acquired by Property Injection. The component name of S2Container is "container".
The following service classes are created as an example. S2Container instance is be DI by automatic Property Injection.

module Example
  class Service
    s2comp
    def initialize
      @container = :container
    end
    attr_reader :container
  end
end

An execution script is created as follows.

require 's2container'
require 'example'

service = s2app.get(Example::Service)
p service.container.class.name
[Note]NOTE

This Example is located in example/example12



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