README.md in smart_container-0.6.0 vs README.md in smart_container-0.7.0

- old
+ new

@@ -43,10 +43,30 @@ # dependencies are not memoized by default (memoize: false) register(:random) { rand(1000) } end ``` +- mixin: + +```ruby +# full documentaiton is coming; + +class Application + include SmartCore::Container::Mixin + + dependencies do + namespace(:database) do + register(:cache) { MemcachedClient.new } + end + end +end + +# access: +Application.container +Application.new.container # NOTE: the same instance as Application.container +``` + - container instantiation and dependency resolving: ```ruby container = Container.new # create container instance ``` @@ -134,20 +154,84 @@ container.dependency?('random', memoized: true) # => false container.dependency?('random', memoized: false) # => true ``` -- state freeze: +- state freeze (`#freeze!`, `.#frozen?`): ```ruby # documentation is coming; ``` -- reloading: +- reloading (`#reload!): ```ruby # documentation is coming; ``` + +- hash tree (`#hash_tree`, `#hash_tree(resolve_dependencies: true)`): + +```ruby +# documentation is coming`; +``` + +- `SmartCore::Container.define` - avoid explicit class definition (allows to create container instance from an anonymous container class immidietly): + +```ruby +# - create from empty container class - + +AppContainer = SmartCore::Container.define do + namespace :database do + register(:logger) { Logger.new } + end +end # => an instance of Class<SmartCore::Container> + +AppContainer.resolve('database.logger') # => #<Logger:0x00007f5f0f2f0158> +AppContainer['database.logger'] # => #<Logger:0x00007f5f0f2f0158> +``` + +```ruby +# - create from another container class with a custom sub-definitions - + +class BasicContainer < SmartCore::Container + namespace(:api) do + register(:client) { Kickbox.new } + end +end + +AppContainer = BasicContainer.define do + register(:db_driver) { Sequel } +end +# --- or --- +AppContainer = SmartCore::Container.define(BasicContainer) do + register(:db_driver) { Sequel } +end + +AppContainer['api.client'] # => #<Kickbox:0x00007f5f0f2f0158> (BasicContainer dependency) +AppContainer['db_driver'] # => Sequel (AppContainer dependency) +``` + +--- + +## Roadmap + +- support for instant dependency registration: + +```ruby +# common (dynamic) way: +register('dependency_name') { dependency_value } + +# instant way: +register('dependency_name', dependency_value) +``` + +- support for memoization ignorance during dependency resolving: + +```ruby +resolve('logger', :allocate) # Draft +``` + +- container composition; --- ## Contributing