diff --git a/packages/email-plugin/src/plugin.spec.ts b/packages/email-plugin/src/plugin.spec.ts index cf9c698db6..e90490f617 100644 --- a/packages/email-plugin/src/plugin.spec.ts +++ b/packages/email-plugin/src/plugin.spec.ts @@ -367,8 +367,8 @@ describe('EmailPlugin', () => { it('loads async data', async () => { const handler = new EmailEventListener('test') .on(MockEvent) - .loadData(async ({ inject }) => { - const service = inject(MockService); + .loadData(async ({ injector }) => { + const service = injector.get(MockService); return service.someAsyncMethod(); }) .setFrom('"test from" ') @@ -398,8 +398,8 @@ describe('EmailPlugin', () => { .setFrom('"test from" ') .setSubject('Hello, {{ testData }}!') .setRecipient(() => 'test@test.com') - .loadData(async ({ inject }) => { - const service = inject(MockService); + .loadData(async ({ injector }) => { + const service = injector.get(MockService); return service.someAsyncMethod(); }) .setTemplateVars(event => ({ testData: event.data })); diff --git a/packages/email-plugin/src/plugin.ts b/packages/email-plugin/src/plugin.ts index 806f4e999a..aee4de564c 100644 --- a/packages/email-plugin/src/plugin.ts +++ b/packages/email-plugin/src/plugin.ts @@ -1,8 +1,8 @@ import { ModuleRef } from '@nestjs/core'; -import { InjectConnection } from '@nestjs/typeorm'; import { createProxyHandler, EventBus, + Injector, JobQueue, JobQueueService, Logger, @@ -10,11 +10,11 @@ import { OnVendureClose, PluginCommonModule, RuntimeVendureConfig, + TransactionalConnection, Type, VendurePlugin, WorkerService, } from '@vendure/core'; -import { Connection } from 'typeorm'; import { isDevModeOptions } from './common'; import { EMAIL_PLUGIN_OPTIONS } from './constants'; @@ -154,7 +154,7 @@ export class EmailPlugin implements OnVendureBootstrap, OnVendureClose { /** @internal */ constructor( private eventBus: EventBus, - @InjectConnection() private connection: Connection, + private connection: TransactionalConnection, private moduleRef: ModuleRef, private workerService: WorkerService, private jobQueueService: JobQueueService, @@ -234,10 +234,10 @@ export class EmailPlugin implements OnVendureBootstrap, OnVendureClose { const { type } = handler; try { if (handler instanceof EmailEventHandlerWithAsyncData) { + const injector = new Injector(this.moduleRef); (event as EventWithAsyncData).data = await handler._loadDataFn({ event, - connection: this.connection, - inject: t => this.moduleRef.get(t, { strict: false }), + injector, }); } const result = await handler.handle(event as any, EmailPlugin.options.globalTemplateVars); diff --git a/packages/email-plugin/src/types.ts b/packages/email-plugin/src/types.ts index f5f03dff2a..dad3559cd9 100644 --- a/packages/email-plugin/src/types.ts +++ b/packages/email-plugin/src/types.ts @@ -1,6 +1,5 @@ import { Omit } from '@vendure/common/lib/omit'; -import { RequestContext, Type, VendureEvent, WorkerMessage } from '@vendure/core'; -import { Connection } from 'typeorm'; +import { Injector, RequestContext, VendureEvent, WorkerMessage } from '@vendure/core'; import { EmailEventHandler } from './event-handler'; @@ -291,8 +290,7 @@ export interface EmailGenerator = (context: { event: Event; - connection: Connection; - inject: (type: Type) => T; + injector: Injector; }) => Promise; export type IntermediateEmailDetails = {