Created
January 31, 2013 10:20
-
-
Save wrozka/4681937 to your computer and use it in GitHub Desktop.
Automated manual dependency injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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