MIF_E31221222/sigap-website/di/container.ts

27 lines
944 B
TypeScript

import { createContainer } from '@evyweb/ioctopus';
import { DI_RETURN_TYPES, DI_SYMBOLS } from '@/di/types';
import { IInstrumentationService } from '@/src/application/services/instrumentation.service.interface';
import { createAuthenticationModule } from './modules/authentication.module';
const ApplicationContainer = createContainer();
ApplicationContainer.load(Symbol('AuthenticationModule'), createAuthenticationModule());
export function getInjection<K extends keyof typeof DI_SYMBOLS>(
symbol: K
): DI_RETURN_TYPES[K] {
const instrumentationService =
ApplicationContainer.get<IInstrumentationService>(
DI_SYMBOLS.IInstrumentationService
);
return instrumentationService.startSpan(
{
name: '(di) getInjection',
op: 'function',
attributes: { symbol: symbol.toString() },
},
() => ApplicationContainer.get(DI_SYMBOLS[symbol])
);
}