InjectableStrategy

InjectableStrategy

InjectableStrategy

This interface defines the setup and teardown hooks available to the various strategies used to configure Vendure.

Signature

interface InjectableStrategy {
  init?: (injector: Injector) => void | Promise<void>;
  destroy?: () => void | Promise<void>;
}

Members

init

property
type:
(injector: Injector) => void | Promise<void>

Defines setup logic to be run during application bootstrap. Receives the Injector as an argument, which allows application providers to be used as part of the setup. This hook will be called on both the main server and the worker processes. If you have code which should only run on either the server on the worker, then inject the ProcessContext to check the current context.

Example

async init(injector: Injector) {
  const processContext = injector.get(ProcessContext);
  if (processContext.isServer) {
    const myService = injector.get(MyService);
    await myService.doSomething();
  }
}

destroy

property
type:
() => void | Promise<void>
Defines teardown logic to be run before application shutdown.