Skip to content

Commit

Permalink
brought back instrumenting the getInjection method
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolovlazar committed Oct 30, 2024
1 parent cced639 commit 7187d72
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions di/container.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import { Container, createContainer } from '@evyweb/ioctopus';
import { createContainer } from '@evyweb/ioctopus';

import { DI_RETURN_TYPES, DI_SYMBOLS } from '@/di/types';

import { IInstrumentationService } from '@/src/application/services/instrumentation.service.interface';

import { registerMonitoringModule } from '@/di/modules/monitoring.module';
import { registerAuthenticationModule } from '@/di/modules/authentication.module';
import { registerTransactionManagerModule } from '@/di/modules/database.module';
import { registerTodosModule } from '@/di/modules/todos.module';
import { registerUsersModule } from '@/di/modules/users.module';
import { DI_RETURN_TYPES, DI_SYMBOLS } from '@/di/types';

const container: Container = createContainer();
const ApplicationContainer = createContainer();

registerMonitoringModule(container);
registerTransactionManagerModule(container);
registerAuthenticationModule(container);
registerUsersModule(container);
registerTodosModule(container);
registerMonitoringModule(ApplicationContainer);
registerTransactionManagerModule(ApplicationContainer);
registerAuthenticationModule(ApplicationContainer);
registerUsersModule(ApplicationContainer);
registerTodosModule(ApplicationContainer);

export function getInjection<T extends keyof DI_RETURN_TYPES>(
key: T
): DI_RETURN_TYPES[T] {
return container.get<DI_RETURN_TYPES[T]>(DI_SYMBOLS[key]);
const instrumentationService =
ApplicationContainer.get<IInstrumentationService>(
DI_SYMBOLS.IInstrumentationService
);

return instrumentationService.startSpan(
{
name: '(di) getInjection',
op: 'function',
attributes: { symbol: key.toString() },
},
() => ApplicationContainer.get<DI_RETURN_TYPES[T]>(DI_SYMBOLS[key])
);
}

0 comments on commit 7187d72

Please sign in to comment.