Overview
With Dependencies, you can replace parts of Spree core with your custom code: Services and Workflows, the staff ability class and the storefront access policy (used for Permissions), and API Serializers (used for generating JSON API responses).Application (global) customization
This will change every aspect of the application (the Store API, the Admin API, and everything built on them). In yourconfig/initializers/spree.rb file, you can set the following:
super keeps Spree’s behaviour and adds yours around it,
which is usually what you want — a full rewrite means re-implementing logic that
changes between releases.
Replacing a workflow
Workflow-backed seams end in_workflow (cart_add_item_workflow,
carts_complete_workflow, payment_capture_workflow, …). A replacement
subclasses the workflow and overrides perform:
Before writing this, check whether a
hook covers your case —
carts.add_item.validate and carts.add_item.after_item_added handle most
reasons people replace this class, and they don’t need maintaining across
upgrades.Using dependencies in your code
When you need to use a dependency in your code, you can access it directly via theSpree module:
Controller level customization
If you need to replace a serializer in a specific API endpoint only, you can create a code decorator:MyNewAwesomeCartSerializer. Services and workflows are resolved through the global dependencies (e.g. Spree.cart_add_item_workflow), so swap those at the application level.
Different API endpoints can have different dependency injection points. You can review their source code to see what you can replace.
API level customization
API serializers have their own injection points underSpree.api — Store API serializers (cart_serializer, product_serializer, …) and Admin API serializers (admin_order_serializer, …) — so you can customize one surface without touching the other.
In your Spree initializer (config/initializers/spree.rb) please add:
Debugging dependencies
Spree provides rake tasks to help you debug and inspect dependencies:List all dependencies
grep to filter results:
Show only overridden dependencies
Validate all dependencies
Programmatic introspection
You can also inspect dependencies programmatically:Seams backed by a workflow
Seams backed by a workflow use a*_workflow name, not *_service:
Two seams are plain renames with an unchanged contract, so an override set
under the old name is still applied (with a deprecation warning):
checkout_add_store_credit_service → store_credit_apply_service and
checkout_remove_store_credit_service → store_credit_remove_service. All
legacy names are removed in Spree 6.1.
Backwards compatibility
The legacy string-based syntax is still supported for backwards compatibility:Default values
Default values can be easily checked by:- Using the rake task:
bin/rake spree:dependencies:list - Looking at the source code:

