Class: IocRb::Scopes::RequestScope
- Defined in:
- lib/ioc_rb/scopes/request_scope.rb
Overview
Request scope instantiates new bean instance on each new HTTP request
Instance Method Summary collapse
-
#delete_bean(bean_metadata) ⇒ Object
Delete bean from scope.
-
#get_bean(bean_metadata) ⇒ Object
Returns a bean from the
RequestStore
RequestStore is a wrapper for Thread.current which clears it on each new HTTP request. -
#initialize(bean_factory) ⇒ RequestScope
constructor
Constructon.
Constructor Details
#initialize(bean_factory) ⇒ RequestScope
Constructon
9 10 11 |
# File 'lib/ioc_rb/scopes/request_scope.rb', line 9 def initialize(bean_factory) @bean_factory = bean_factory end |
Instance Method Details
#delete_bean(bean_metadata) ⇒ Object
Delete bean from scope
30 31 32 |
# File 'lib/ioc_rb/scopes/request_scope.rb', line 30 def delete_bean() RequestStore.store[:_iocrb_beans].delete(.name) end |
#get_bean(bean_metadata) ⇒ Object
Returns a bean from the RequestStore
RequestStore is a wrapper for Thread.current which clears it on each new HTTP request
19 20 21 22 23 24 25 26 |
# File 'lib/ioc_rb/scopes/request_scope.rb', line 19 def get_bean() RequestStore.store[:_iocrb_beans] ||= {} if bean = RequestStore.store[:_iocrb_beans][.name] bean else @bean_factory.create_bean_and_save(, RequestStore.store[:_iocrb_beans]) end end |