Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Order state machine hooks injectable #401

Closed
michaelbromley opened this issue Jul 6, 2020 · 0 comments
Closed

Make Order state machine hooks injectable #401

michaelbromley opened this issue Jul 6, 2020 · 0 comments
Milestone

Comments

@michaelbromley
Copy link
Member

Is your feature request related to a problem? Please describe.
In OrderProcessOptions we allow the developer to define hooks to control/interact with state transitions of the Order state machine. However, there is no opportunity to inject services or other providers, which limits the usefulness of this feature.

In #303 we created a pattern to enable injection in to most other configurable processes but failed to consider this one.

Describe the solution you'd like
There are 2 ways I can think to solve this:

  1. Add a 4th injector argument to each callback. This would be relatively simple to implement and would not break any existing code.
  2. Re-work the way these hooks are defined so that we have a new OrderProcessStrategy interface which implements InjectableStrategy. This interface would have optional methods for each of the existing hooks, and also allow injection (+ setup/teardown).

I am tending towards option 2 because:

  • It is consistent with the conventions used by Vendure
  • It would make it easier to compose multiple state transition hooks since we would accept an array of OrderProcessStrategy objects and execute each hook in turn in the order that they are defined.

We could do this in a non-breaking way by keeping the existing options but marking the callback methods as deprecated and eventually removing them in some future version.

michaelbromley added a commit that referenced this issue Jul 9, 2020
This commit enables composition of multiple new custom order process states, and also makes it possible to inject providers into the transition hooks. Relates to #401

BREAKING CHANGE: The way custom Order states are defined has changed. The `VendureConfig.orderOptions.process` property now accepts an **array** of objects implementing the `CustomerOrderProcess` interface. This interface is more-or-less the same as the old `OrderProcessOptions` object, but the use of an array now allows better composition, and since `CustomerOrderProcess` inherits from `InjectableStrategy`, this means providers can now be injected and used in the custom order process logic.
@michaelbromley michaelbromley added this to the v0.14.0 milestone Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant