NOTE: I am in the process of extracting dependency injection features from Gaug.es. Currently, the only feature of this library is memoization. I am not dumb or inexperienced. I'm just not done yet.
Morphine is a lightweight dependency injection framework for Ruby. It uses a simple Ruby DSL to ease the pain of wiring your dependencies together.
Create a container for your dependencies and include the
class Application include Morphine register :track_service do KestrelTrackService.new(kestrel_client, config.tracking_queue) end register :track_processor do KestrelTrackProcessor.new(blocking_kestrel_client, config.tracking_queue) end private register :kestrel_client do c = config['kestrel'].dup Kestrel::Client.new(c.delete('servers'), c.symbolize_keys) end register :blocking_kestrel_client do Kestrel::Client::Blocking.new(kestrel_client) end end
Create an instance of your container, and use that to load your dependencies
$app = Application.new get '/track.gif' do $app.track_processor.record(params['h']) end
That's why Morphine is an extremely simple library.
If you find what looks like a bug:
- Check the GitHub issue tracker to see if anyone else has reported issue.
- If you don't see anything, create an issue with information on how to reproduce it.
If you want to contribute an enhancement or a fix:
- Fork the project on GitHub.
- Make your changes with tests.
- Commit the changes without making changes to the Rakefile, Gemfile, gemspec, or any other files that aren't related to your enhancement or fix
- Send a pull request.