class IocRb::Scopes::RequestScope

Request scope instantiates new bean instance on each new HTTP request

Public Class Methods

new(bean_factory) click to toggle source

Constructon @param bean_factory bean factory

# File lib/ioc_rb/scopes/request_scope.rb, line 9
def initialize(bean_factory)
  @bean_factory = bean_factory
end

Public Instance Methods

delete_bean(bean_metadata) click to toggle source

Delete bean from scope @param bean_metadata [BeanMetadata] bean metadata

# File lib/ioc_rb/scopes/request_scope.rb, line 30
def delete_bean(bean_metadata)
  RequestStore.store[:_iocrb_beans].delete(bean_metadata.name)
end
get_bean(bean_metadata) click to toggle source

Returns a bean from the RequestStore RequestStore is a wrapper for Thread.current which clears it on each new HTTP request

@param bean_metadata [BeanMetadata] bean metadata @returns bean instance

# File lib/ioc_rb/scopes/request_scope.rb, line 19
def get_bean(bean_metadata)
  RequestStore.store[:_iocrb_beans] ||= {}
  if bean = RequestStore.store[:_iocrb_beans][bean_metadata.name]
    bean
  else
   @bean_factory.create_bean_and_save(bean_metadata, RequestStore.store[:_iocrb_beans])
  end
end