workflow-core icon indicating copy to clipboard operation
workflow-core copied to clipboard

Virtual persistence provider methods

Open BalazsArva opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe. I'm submitting a feature request to change the interface methods of persistence providers to virtual, so they can be customized by developers.

Describe the solution you'd like Persistence provider methods are virtual, allowing developers to alter/extend their behavior.

Describe alternatives you've considered Calling into the existing one(s) from within a wrapper class, and adding the customized behavior to the wrapper methods. Works, but overly complicated.

Additional context Currently, the interface methods of persistence providers (used MongoDB persistence provider) are not virtual, so the only way to execute additional code is by wrapping the provided MongoPersistenceProvider in a custom class, which implements the appropriate interfaces and forwards the calls into the wrapped object, before and/or after any additional code is executed.

I came accross this when I wanted to implement change tracking with outbox pattern: every time a workflow is created/updated, I needed to capture the resulting state, save that into a dedicated collection right after the core persistence logic has succeeded. A background worker would read from this collection to process the entities in it, e.g. by publishing change notification messages to a pub/sub system. Consumers could then pick these up and do whatever they want, e.g. build a searchable list, do aggregations, calculate stats and metrics and whatever else. To be clear, I'm not asking for an out of the box change tracking solution, this is merely a realistic example for when devs may need to add some more logic besides what's already done by the currently existing providers. In such cases, overriding existing methods is much more convenient than implementing a wrapper class.

BalazsArva avatar Jan 21 '22 09:01 BalazsArva