Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Data Injectors

Data Injectors

Cortex provides a number of data injectors for injecting data into prototype instances. Resource identifier annotations are always accompanied by an @Inject annotation. For more information and examples on when and how to use data injectors, see Resource Identifiers.

Data injectors can be put into two main categories: contextual data injectors and request data injectors.

Contextual Data Injectors

Annotation Description

Inject the currency, Currency.


Inject the current User ID String.


Inject the locale Locale.


Injects all scopes if the annotated type is Iterable<String>.


Inject the scope Subject.

Request Data Injectors

Annotation Description

Inject a ResourceEntity that encapsulates the input data.


Inject a ResourceIdentifier.


Inject an IdentifierPart. This reference can be typed, such as IdentifierPart<String>.

Using @RequestForm Data Injectors

The @RequestForm data injector injects a ResourceEntity into a Prototype instance.

A ResourceEntity is a representation of the input form data submitted by the client. The @RequestForm data injector should be used in the context of a PUT or Create operation. In some cases a client may not submit any form data, thus the ResourceEntity to inject would not be present.

The default usage of the @RequestForm data injector is:

  private MyResourceEntity entity

If a client tries to submit an empty form, the injection will fail and a HTTP Bad Request (status code 400) response will be returned to the client.

If you would like to define their own empty form handling behavior, inject a ResourceEntity typed Optional. In the case of an empty form the Optional would be absent.

  private Optional<MyResourceEntity> maybeEntity

OSGi Service Injectors

Annotation Description

Inject a Repository typed to a specific ResourceEntity and ResourceIdentifier.


Inject an OSGi Service.

Using @ResourceRepository Data Injectors

The @ResourceRepository data injector injects a Repository typed to a specific ResourceEntity and ResourceIdentifier into a Prototype instance.

The default usage of the @ResourceRepository data injector is:

  Repository<MyResourceEntity, MyResourceIdentifier> repository
Note: Note: Injecting an OSGI service in non-prototype classes, e.g. a PermissionParameterStrategy, with @ResourceRepository or @ResourceService will not work unless the services are already injected (i.e. active) in a prototype class. However, you can inject such a service via configurePrototypes method of the resource Wiring class, see Configuring Prototypes.

Enabling Validation for Data Injectors

You can enable compile-time validation to ensure that data injections are of the correct type required. To enable validation, see Enabling Validation.