Skip to content

Instantly share code, notes, and snippets.

@wrozka
Created January 31, 2013 10:20
Show Gist options
  • Save wrozka/4681937 to your computer and use it in GitHub Desktop.
Save wrozka/4681937 to your computer and use it in GitHub Desktop.
Automated manual dependency injection
require 'dependor'
require 'dependor/shorty' # to enable takes syntax
module HasClassName
def name
self.class.name
end
end
class UserFinder
include HasClassName
end
class UserStatusReader
include HasClassName
end
class Thing
takes :user_finder, :user_status_reader
def combined_names
"#{user_finder.name} and #{user_status_reader.name}"
end
end
class Injector
include Dependor::AutoInject
end
injector = Injector.new
thing = injector.thing # no wiring required
puts "The combined names are: #{thing.combined_names}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment