Skip to content
Vladislav Trotsenko edited this page Apr 10, 2020 · 2 revisions

Synopsis

Provides to set dependency injection in operations.

Examples of usage

Inject dependencies from Dry::Container

class Container
  extend Dry::Container::Mixin
  namespace 'some_namespace' { register('some_dependency') { SomeDependency } }
end

class SomeOperation < ApplicationOperation
  step Macro::Inject(some_dependency: 'some_namespace.some_dependency') # ctx[:some_dependency] = SomeDependency
end

Inject dependencies directly

class SomeOperation < ApplicationOperation
  step Macro::Inject(some_dependency: SomeDependency, other_dependency: OtherDependency)
  # ctx[:some_dependency], ctx[:other_dependency] = SomeDependency, OtherDependency
end

Inject of both types dependencies

class SomeOperation < ApplicationOperation
  step Macro::Inject(some_dependency: 'some_namespace.some_dependency', other_dependency: OtherDependency)
  # ctx[:some_dependency], ctx[:other_dependency] = SomeDependency, OtherDependency
end
Clone this wiki locally