Skip to content

Dependency injection #70

@fidalgo

Description

@fidalgo

First of all, thank you for the work in this lib! I've found it very useful and I'm giving it a go in a personal project to play around.
I've found a hurdle that I would appreciate if you can provide some tips on how to proceed, hopefully, it could help others as well.

I see play as a way of dependency injection, although inside of an actor I would like to call another actor and perform some logic basic on inputs and outputs.

class ServiceClient < Actor
  input :token, allow_nil: false
  input :term, allow_nil: false

  def call
    Faraday.new('http://example.com/service').get("", query: term)
  end
end
class Persistor < Actor
  input :client, default: ServiceClient
  
  def class
    outcome = ServiceClient.result(token: 'token', term: 'actor')
    puts outcome.status   if outcome.success?
  end
end

The problem is when I use input :client, default: ServiceClient it tries to initialize the class and then failed because of the missing required arguments. If I move provider as a private method it works.

Is there any way to achieve dependency injection?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions