Dee
Simple DI Container/Service Locator for Ruby
Installation
Add this line to your application's Gemfile:
gem 'dee'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dee
Usage
Foo = Struct.new(:name)
container = Dee::Container.new
# Define a value
container['foo.name'] = 'FOO'
# Define a factory
container.factory 'foo' do
Foo.new(container['foo.name'])
end
# Define a singleton factory
container.singleton 'foo.singleton' do
Foo.new(container['foo.name'])
end
# Create Foo object
# This creates Foo object everytime
foo = container['foo']
# Create singleton Foo object
# This creates Foo object only at the first time
# And it returns same object after the creation
foo = container['foo.singleton']
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request