Open paul opened 5 years ago
š
Is there is some workaround? The best solution I've is
class GreatJob < ApplicationJob
def perform(payload)
repo.save payload
end
def repo
ApplicationContainer.resolve(:repo)
end
end
We should properly document that using auto-inject in classes that you don't own is not recommended as there can be incompatibility with constructors. auto-inject does its best to determine super constructor's behavior and act accordingly but sometimes it's just not possible.
One solution would be to add another strategy that uses attribute readers that do exactly what repo
method does in your example, the only trick is that those should be memoized.
@timriley WDYT about that? āš»
or use effects... Though, for effects you'll also need a handler somewhere so setup a bit more involved
I think #48 broke the ability to use AutoInject in ActiveJob classes.
We have a Job that looks like this:
The Channels container has registered
:account_channel
as simplyAccountChannel
.When I upgraded the AutoInject gem from 0.4.6 to 0.6.0, I get an error in my specs:
I tossed a debugger in the enqueue process, and in 0.4.8 it attempts to serialize the
@arguments
, which looks like this:In 0.6.0, however, now
@arguments
includes the injected AccountChannel:If I'm understanding it right, I seems #48 changed the initializer from removing the keys it knows about from the kwargs passed to the inheriting class, to instead just passing everything through if the class's
#initialize
function splats its args?One of my prime use-cases for dry-container/auto_inject was to get around the brain-dead way ActiveJob handles initialization, because it can't differentiate between kwargs passed to the initializer for DI, and params passed to the
#perform
method to do the work. It was really nice that Dry::AutoInject allowed us to do that without having to jump through a bunch of hoops.48 mentioned possible breakage in Rails Controllers, could something like that be adapted to work with ActiveJob?