Class: IocRb::Scopes::SingletonScope
- Defined in:
- lib/ioc_rb/scopes/singleton_scope.rb
Overview
Singleton scope returns the same bean instance on each call
Instance Method Summary collapse
-
#delete_bean(bean_metadata) ⇒ Object
Delete bean from scope.
-
#get_bean(bean_metadata) ⇒ Object
Returns the same bean instance on each call.
-
#initialize(bean_factory) ⇒ SingletonScope
constructor
Constructon.
Constructor Details
#initialize(bean_factory) ⇒ SingletonScope
Constructon
7 8 9 10 |
# File 'lib/ioc_rb/scopes/singleton_scope.rb', line 7 def initialize(bean_factory) @beans = {} @bean_factory = bean_factory end |
Instance Method Details
#delete_bean(bean_metadata) ⇒ Object
Delete bean from scope
26 27 28 |
# File 'lib/ioc_rb/scopes/singleton_scope.rb', line 26 def delete_bean() @beans.delete(.name) end |
#get_bean(bean_metadata) ⇒ Object
Returns the same bean instance on each call
16 17 18 19 20 21 22 |
# File 'lib/ioc_rb/scopes/singleton_scope.rb', line 16 def get_bean() if bean = @beans[.name] bean else @bean_factory.create_bean_and_save(, @beans) end end |