cookie-cutter
cookie-cutter copied to clipboard
Service dependency injection lifecycle to create a new instance on each message
it appears to me that when using the service injection allows only one instance per application life-cycle, but no ability to create a one instance per message life-cycle.
Use case: We have a service that we hit to read in a list of items then we use these items within the handler for the messages. We would like to cache the result in the service code so that if the handler calls it more then once it does not make the big call again. But we don't want the cache to be used on the next message, we want that one to have its own cache. We can then use Dataloader library and have it do its cacheing as expected and a new instance of it created on the next message.
We can call a method on the service interface at the start of each message to clear the cache, or at the end to clear the cache. But a number of dependency injection libraries support different life-cycle modes.
Do you know if there are any good dependency injection libraries for JavaScript / TypeScript that support all of this? I am wondering if it would make more sense to only provide a Service Locator
API / abstraction in Cookie Cutter and then allow DI libraries to plugin there.