fix: make metadata key's constants
This commit is contained in:
+5
-2
@@ -1,15 +1,18 @@
|
||||
import type { ServiceIdentifier } from './types.js';
|
||||
|
||||
export const DI_PARAM_TYPES = 'di:paramtypes';
|
||||
export const DI_INJECTABLE = 'di:injectable';
|
||||
|
||||
export function inject<T>(serviceType: ServiceIdentifier<T>): ParameterDecorator {
|
||||
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
|
||||
return (target: Object, _: string | symbol | undefined, parameterIndex: number) => {
|
||||
Reflect.defineMetadata('di:paramtypes', serviceType, target, parameterIndex.toString());
|
||||
Reflect.defineMetadata(DI_PARAM_TYPES, serviceType, target, parameterIndex.toString());
|
||||
};
|
||||
}
|
||||
|
||||
export function injectable(): ClassDecorator {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
return (target: Function) => {
|
||||
Reflect.defineMetadata('di:injectable', true, target);
|
||||
Reflect.defineMetadata(DI_INJECTABLE, true, target);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DI_PARAM_TYPES } from './decorators.js';
|
||||
import type {
|
||||
IServiceProvider,
|
||||
IServiceScope,
|
||||
@@ -93,7 +94,7 @@ export class ServiceProvider implements IServiceProvider {
|
||||
|
||||
const params = paramTypes.map((_: unknown, index: number) => {
|
||||
const serviceType = Reflect.getMetadata(
|
||||
'di:paramtypes',
|
||||
DI_PARAM_TYPES,
|
||||
ctor,
|
||||
index.toString(),
|
||||
) as ServiceIdentifier<unknown>;
|
||||
|
||||
Reference in New Issue
Block a user