Pawel Pierzchala @zwrozka
DRUG 20.05.2013
class PeopleController
def create
person_repository.add(params)
end
private
def person_repository
PersonRepository.new(current_trip)
end
end
yet another resource
class RoomAssignmentsController
def create
room_assignments.add(params)
end
private
def room_assignments
RoomAssignments.new(person_repository, room_repository)
end
end
don't call us, we'll call you
Dependency Injection
def person_repository(current_trip)
PersonRepository.new(current_trip)
end
def room_assignments
RoomAssignments.new(person_repository, room_repository)
end
# noop
class Injector
include Dependor::AutoInject
attr_reader :current_trip
def initalize(current_trip)
@current_trip = current_trip
end
end
def room_assignments
RoomAssignments.new(person_repository, room_repository)
end
def room_assignments
Injector.new(current_trip).room_assignments
end
inject :room_assignments
class ApplicationController
extend Dependor::Injectable
def injector
Injector.new(current_trip)
end
end
class RoomAssignments
def initalize(person_repository, rooms_repository)
@person_repository = person_repository
@room_repository = room_repository
end
private
attr_reader :person_repository, :room_repository
end
class RoomAssignments
takes :person_repository, :room_repository
end
Any questions?