You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
Hi there! I haven’t used actors for dependency injection, so I hadn’t encountered this use-case before. It looks very versatile though, I can think of a few places where this would be very handy in my code!
The issue here is that in order to handle dynamic defaults, the default: keyword tries to trigger .call on whatever is given to it (if it responds to that method). This works well for lambdas, but not so much for actors themselves.
Therefore, one way to fix this is to define the default inside a lambda, as so:
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.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 moveprovider
as a private method it works.Is there any way to achieve dependency injection?
The text was updated successfully, but these errors were encountered: