From c9ec1c356edfc312c7cc3b9fa5b25e8ac53cb05b Mon Sep 17 00:00:00 2001 From: Thomas Cruveilher <38007824+Sorikairox@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:48:43 +0000 Subject: [PATCH] feat: bring back TokenInjector for backward compatibility --- spec/injection.test.ts | 7 ++----- src/injector/injectable/constructor.ts | 4 ++++ src/router/websocket/payload.ts | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/spec/injection.test.ts b/spec/injection.test.ts index 5f1670cf..653a4ae1 100644 --- a/spec/injection.test.ts +++ b/spec/injection.test.ts @@ -13,7 +13,7 @@ import { Module, ModuleMetadata } from '../src/module/decorator.ts'; import { Controller, Get, Post } from '../src/router/controller/decorator.ts'; import { HttpContext } from '../src/router/router.ts'; import { injector } from '../src/injector/injector.ts'; -import { Injector } from '../mod.ts'; +import { Injector, TokenInjector } from '../mod.ts'; Deno.test('Injection', async (testContext) => { interface IDBService { @@ -106,10 +106,7 @@ Deno.test('Injection', async (testContext) => { controllers: [SingletonController], injectables: [ GlobalInjectable, - { - token: 'DB_SERVICE', - useClass: DatabaseService, - }, + new TokenInjector(DatabaseService, 'DB_SERVICE'), { token: 'CONFIGURATION', useValue: { diff --git a/src/injector/injectable/constructor.ts b/src/injector/injectable/constructor.ts index 657038c7..6797b4a8 100644 --- a/src/injector/injectable/constructor.ts +++ b/src/injector/injectable/constructor.ts @@ -1,6 +1,10 @@ import { Constructor } from '../../utils/constructor.ts'; export type InjectableConstructor = Constructor; +export class TokenInjector { + constructor(public useClass: InjectableConstructor, public token: string) { + } +} export type UseClassInjector = { useClass: InjectableConstructor; token: string; diff --git a/src/router/websocket/payload.ts b/src/router/websocket/payload.ts index 7d88c02b..3c2a91fe 100644 --- a/src/router/websocket/payload.ts +++ b/src/router/websocket/payload.ts @@ -1,4 +1,4 @@ export interface WebSocketPayload { - topic: string; - data: T -} \ No newline at end of file + topic: string; + data: T; +}