Turning off dry-auto_inject memoization


I’m using dry-system to sort out dependencies for a Sinatra app (and stub them out in my tests).

Unfortunately – to the best of my understanding of my current situation, I’ll be so happy to be wrong here :wink: – a Sinatra app is a singleton. In my case Deps is a subclass of Dry::System::Container and I

include Deps.injector['foo']

in my Sinatra app.

In my testing suite separate tests do their own Deps.stub('foo', fake(Foo)) / Deps.unstub dances; unfortunately the app (being a singleton with memoized foo result) only ever tries to opearate on the first test’s fake – the tests pass in insolation and break when ran together.

I think this is a memoization issue, because adding the below to my app solves the problem:

def foo

– in this case the proper fakes are being fetched.

Is there an option I can pass through to dry-auto_inject to stop it from memoizing, but rather make proper Deps['foo'] calls on every foo call?


Any chance you could show a working example of this?