From 23114fe5ddc671f1cd6132b9d959367f6c507b57 Mon Sep 17 00:00:00 2001 From: Lazar Nikolov Date: Wed, 30 Oct 2024 10:58:21 -0400 Subject: [PATCH] renaming DI and DI_TYPES like previously named DI_SYMBOLS and DI_RETURN_TYPES --- di/container.ts | 8 ++-- di/modules/authentication.module.ts | 40 ++++++++-------- di/modules/database.module.ts | 6 +-- di/modules/monitoring.module.ts | 16 +++++-- di/modules/todos.module.ts | 72 ++++++++++++++--------------- di/modules/users.module.ts | 44 ++++++++++-------- di/types.ts | 4 +- 7 files changed, 104 insertions(+), 86 deletions(-) diff --git a/di/container.ts b/di/container.ts index 4420b9b..f8cfc8f 100644 --- a/di/container.ts +++ b/di/container.ts @@ -5,7 +5,7 @@ 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_TYPES, DI } from '@/di/types'; +import { DI_RETURN_TYPES, DI_SYMBOLS } from '@/di/types'; const container: Container = createContainer(); @@ -15,6 +15,8 @@ registerAuthenticationModule(container); registerUsersModule(container); registerTodosModule(container); -export function getInjection(key: T): DI_TYPES[T] { - return container.get(DI[key]); +export function getInjection( + key: T +): DI_RETURN_TYPES[T] { + return container.get(DI_SYMBOLS[key]); } diff --git a/di/modules/authentication.module.ts b/di/modules/authentication.module.ts index ffc1cc9..09c3708 100644 --- a/di/modules/authentication.module.ts +++ b/di/modules/authentication.module.ts @@ -7,37 +7,41 @@ import { signInController } from '@/src/interface-adapters/controllers/auth/sign import { signOutController } from '@/src/interface-adapters/controllers/auth/sign-out.controller'; import { signUpController } from '@/src/interface-adapters/controllers/auth/sign-up.controller'; -import { DI } from '@/di/types'; +import { DI_SYMBOLS } from '@/di/types'; export function registerAuthenticationModule(container: Container) { if (process.env.NODE_ENV === 'test') { container - .bind(DI.IAuthenticationService) - .toClass(MockAuthenticationService, [DI.IUsersRepository]); + .bind(DI_SYMBOLS.IAuthenticationService) + .toClass(MockAuthenticationService, [DI_SYMBOLS.IUsersRepository]); } else { container - .bind(DI.IAuthenticationService) + .bind(DI_SYMBOLS.IAuthenticationService) .toClass(AuthenticationService, [ - DI.IUsersRepository, - DI.IInstrumentationService, + DI_SYMBOLS.IUsersRepository, + DI_SYMBOLS.IInstrumentationService, ]); } - container.bind(DI.ISignInController).toHigherOrderFunction(signInController, { - instrumentationService: DI.IInstrumentationService, - signInUseCase: DI.ISignInUseCase, - }); + container + .bind(DI_SYMBOLS.ISignInController) + .toHigherOrderFunction(signInController, { + instrumentationService: DI_SYMBOLS.IInstrumentationService, + signInUseCase: DI_SYMBOLS.ISignInUseCase, + }); container - .bind(DI.ISignOutController) + .bind(DI_SYMBOLS.ISignOutController) .toHigherOrderFunction(signOutController, { - instrumentationService: DI.IInstrumentationService, - authenticationService: DI.IAuthenticationService, - signOutUseCase: DI.ISignOutUseCase, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + authenticationService: DI_SYMBOLS.IAuthenticationService, + signOutUseCase: DI_SYMBOLS.ISignOutUseCase, }); - container.bind(DI.ISignUpController).toHigherOrderFunction(signUpController, { - instrumentationService: DI.IInstrumentationService, - signUpUseCase: DI.ISignUpUseCase, - }); + container + .bind(DI_SYMBOLS.ISignUpController) + .toHigherOrderFunction(signUpController, { + instrumentationService: DI_SYMBOLS.IInstrumentationService, + signUpUseCase: DI_SYMBOLS.ISignUpUseCase, + }); } diff --git a/di/modules/database.module.ts b/di/modules/database.module.ts index 9faeae6..e279d76 100644 --- a/di/modules/database.module.ts +++ b/di/modules/database.module.ts @@ -3,16 +3,16 @@ import { Container } from '@evyweb/ioctopus'; import { TransactionManagerService } from '@/src/infrastructure/services/transaction-manager.service'; import { MockTransactionManagerService } from '@/src/infrastructure/services/transaction-manager.service.mock'; -import { DI } from '@/di/types'; +import { DI_SYMBOLS } from '@/di/types'; export function registerTransactionManagerModule(container: Container) { if (process.env.NODE_ENV === 'test') { container - .bind(DI.ITransactionManagerService) + .bind(DI_SYMBOLS.ITransactionManagerService) .toClass(MockTransactionManagerService); } else { container - .bind(DI.ITransactionManagerService) + .bind(DI_SYMBOLS.ITransactionManagerService) .toClass(TransactionManagerService); } } diff --git a/di/modules/monitoring.module.ts b/di/modules/monitoring.module.ts index 238cdcb..eba002c 100644 --- a/di/modules/monitoring.module.ts +++ b/di/modules/monitoring.module.ts @@ -5,16 +5,22 @@ import { InstrumentationService } from '@/src/infrastructure/services/instrument import { MockCrashReporterService } from '@/src/infrastructure/services/crash-reporter.service.mock'; import { CrashReporterService } from '@/src/infrastructure/services/crash-reporter.service'; -import { DI } from '@/di/types'; +import { DI_SYMBOLS } from '@/di/types'; export function registerMonitoringModule(container: Container) { if (process.env.NODE_ENV === 'test') { container - .bind(DI.IInstrumentationService) + .bind(DI_SYMBOLS.IInstrumentationService) .toClass(MockInstrumentationService); - container.bind(DI.ICrashReporterService).toClass(MockCrashReporterService); + container + .bind(DI_SYMBOLS.ICrashReporterService) + .toClass(MockCrashReporterService); } else { - container.bind(DI.IInstrumentationService).toClass(InstrumentationService); - container.bind(DI.ICrashReporterService).toClass(CrashReporterService); + container + .bind(DI_SYMBOLS.IInstrumentationService) + .toClass(InstrumentationService); + container + .bind(DI_SYMBOLS.ICrashReporterService) + .toClass(CrashReporterService); } } diff --git a/di/modules/todos.module.ts b/di/modules/todos.module.ts index 55d458c..f108f82 100644 --- a/di/modules/todos.module.ts +++ b/di/modules/todos.module.ts @@ -13,80 +13,80 @@ import { createTodoController } from '@/src/interface-adapters/controllers/todos import { getTodosForUserController } from '@/src/interface-adapters/controllers/todos/get-todos-for-user.controller'; import { toggleTodoController } from '@/src/interface-adapters/controllers/todos/toggle-todo.controller'; -import { DI } from '@/di/types'; +import { DI_SYMBOLS } from '@/di/types'; export function registerTodosModule(container: Container) { if (process.env.NODE_ENV === 'test') { - container.bind(DI.ITodosRepository).toClass(MockTodosRepository); + container.bind(DI_SYMBOLS.ITodosRepository).toClass(MockTodosRepository); } else { container - .bind(DI.ITodosRepository) + .bind(DI_SYMBOLS.ITodosRepository) .toClass(TodosRepository, [ - DI.IInstrumentationService, - DI.ICrashReporterService, + DI_SYMBOLS.IInstrumentationService, + DI_SYMBOLS.ICrashReporterService, ]); } container - .bind(DI.ICreateTodoUseCase) + .bind(DI_SYMBOLS.ICreateTodoUseCase) .toHigherOrderFunction(createTodoUseCase, { - instrumentationService: DI.IInstrumentationService, - todosRepository: DI.ITodosRepository, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + todosRepository: DI_SYMBOLS.ITodosRepository, }); container - .bind(DI.IDeleteTodoUseCase) + .bind(DI_SYMBOLS.IDeleteTodoUseCase) .toHigherOrderFunction(deleteTodoUseCase, { - instrumentationService: DI.IInstrumentationService, - todosRepository: DI.ITodosRepository, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + todosRepository: DI_SYMBOLS.ITodosRepository, }); container - .bind(DI.IGetTodosForUserUseCase) + .bind(DI_SYMBOLS.IGetTodosForUserUseCase) .toHigherOrderFunction(getTodosForUserUseCase, { - instrumentationService: DI.IInstrumentationService, - todosRepository: DI.ITodosRepository, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + todosRepository: DI_SYMBOLS.ITodosRepository, }); container - .bind(DI.IToggleTodoUseCase) + .bind(DI_SYMBOLS.IToggleTodoUseCase) .toHigherOrderFunction(toggleTodoUseCase, { - instrumentationService: DI.IInstrumentationService, - todosRepository: DI.ITodosRepository, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + todosRepository: DI_SYMBOLS.ITodosRepository, }); container - .bind(DI.IBulkUpdateController) + .bind(DI_SYMBOLS.IBulkUpdateController) .toHigherOrderFunction(bulkUpdateController, { - instrumentationService: DI.IInstrumentationService, - authenticationService: DI.IAuthenticationService, - transactionManagerService: DI.ITransactionManagerService, - toggleTodoUseCase: DI.IToggleTodoUseCase, - deleteTodoUseCase: DI.IDeleteTodoUseCase, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + authenticationService: DI_SYMBOLS.IAuthenticationService, + transactionManagerService: DI_SYMBOLS.ITransactionManagerService, + toggleTodoUseCase: DI_SYMBOLS.IToggleTodoUseCase, + deleteTodoUseCase: DI_SYMBOLS.IDeleteTodoUseCase, }); container - .bind(DI.ICreateTodoController) + .bind(DI_SYMBOLS.ICreateTodoController) .toHigherOrderFunction(createTodoController, { - instrumentationService: DI.IInstrumentationService, - authenticationService: DI.IAuthenticationService, - transactionManagerService: DI.ITransactionManagerService, - createTodoUseCase: DI.ICreateTodoUseCase, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + authenticationService: DI_SYMBOLS.IAuthenticationService, + transactionManagerService: DI_SYMBOLS.ITransactionManagerService, + createTodoUseCase: DI_SYMBOLS.ICreateTodoUseCase, }); container - .bind(DI.IGetTodosForUserController) + .bind(DI_SYMBOLS.IGetTodosForUserController) .toHigherOrderFunction(getTodosForUserController, { - instrumentationService: DI.IInstrumentationService, - getTodosForUserUseCase: DI.IGetTodosForUserUseCase, - authenticationService: DI.IAuthenticationService, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + getTodosForUserUseCase: DI_SYMBOLS.IGetTodosForUserUseCase, + authenticationService: DI_SYMBOLS.IAuthenticationService, }); container - .bind(DI.IToggleTodoController) + .bind(DI_SYMBOLS.IToggleTodoController) .toHigherOrderFunction(toggleTodoController, { - instrumentationService: DI.IInstrumentationService, - toggleTodoUseCase: DI.IToggleTodoUseCase, - authenticationService: DI.IAuthenticationService, + instrumentationService: DI_SYMBOLS.IInstrumentationService, + toggleTodoUseCase: DI_SYMBOLS.IToggleTodoUseCase, + authenticationService: DI_SYMBOLS.IAuthenticationService, }); } diff --git a/di/modules/users.module.ts b/di/modules/users.module.ts index 28b2957..77eee15 100644 --- a/di/modules/users.module.ts +++ b/di/modules/users.module.ts @@ -7,34 +7,40 @@ import { signInUseCase } from '@/src/application/use-cases/auth/sign-in.use-case import { signUpUseCase } from '@/src/application/use-cases/auth/sign-up.use-case'; import { signOutUseCase } from '@/src/application/use-cases/auth/sign-out.use-case'; -import { DI } from '@/di/types'; +import { DI_SYMBOLS } from '@/di/types'; export function registerUsersModule(container: Container) { if (process.env.NODE_ENV === 'test') { - container.bind(DI.IUsersRepository).toClass(MockUsersRepository); + container.bind(DI_SYMBOLS.IUsersRepository).toClass(MockUsersRepository); } else { container - .bind(DI.IUsersRepository) + .bind(DI_SYMBOLS.IUsersRepository) .toClass(UsersRepository, [ - DI.IInstrumentationService, - DI.ICrashReporterService, + DI_SYMBOLS.IInstrumentationService, + DI_SYMBOLS.ICrashReporterService, ]); } - container.bind(DI.ISignInUseCase).toHigherOrderFunction(signInUseCase, { - instrumentationService: DI.IInstrumentationService, - authenticationService: DI.IAuthenticationService, - usersRepository: DI.IUsersRepository, - }); + container + .bind(DI_SYMBOLS.ISignInUseCase) + .toHigherOrderFunction(signInUseCase, { + instrumentationService: DI_SYMBOLS.IInstrumentationService, + authenticationService: DI_SYMBOLS.IAuthenticationService, + usersRepository: DI_SYMBOLS.IUsersRepository, + }); - container.bind(DI.ISignOutUseCase).toHigherOrderFunction(signOutUseCase, { - instrumentationService: DI.IInstrumentationService, - authenticationService: DI.IAuthenticationService, - }); + container + .bind(DI_SYMBOLS.ISignOutUseCase) + .toHigherOrderFunction(signOutUseCase, { + instrumentationService: DI_SYMBOLS.IInstrumentationService, + authenticationService: DI_SYMBOLS.IAuthenticationService, + }); - container.bind(DI.ISignUpUseCase).toHigherOrderFunction(signUpUseCase, { - instrumentationService: DI.IInstrumentationService, - authenticationService: DI.IAuthenticationService, - usersRepository: DI.IUsersRepository, - }); + container + .bind(DI_SYMBOLS.ISignUpUseCase) + .toHigherOrderFunction(signUpUseCase, { + instrumentationService: DI_SYMBOLS.IInstrumentationService, + authenticationService: DI_SYMBOLS.IAuthenticationService, + usersRepository: DI_SYMBOLS.IUsersRepository, + }); } diff --git a/di/types.ts b/di/types.ts index c003122..6c2fae8 100644 --- a/di/types.ts +++ b/di/types.ts @@ -22,7 +22,7 @@ import { ICreateTodoController } from '@/src/interface-adapters/controllers/todo import { IGetTodosForUserController } from '@/src/interface-adapters/controllers/todos/get-todos-for-user.controller'; import { IToggleTodoController } from '@/src/interface-adapters/controllers/todos/toggle-todo.controller'; -export const DI = { +export const DI_SYMBOLS = { // Services IAuthenticationService: Symbol.for('IAuthenticationService'), ITransactionManagerService: Symbol.for('ITransactionManagerService'), @@ -52,7 +52,7 @@ export const DI = { IToggleTodoController: Symbol.for('IToggleTodoController'), }; -export type DI_TYPES = { +export type DI_RETURN_TYPES = { // Services IAuthenticationService: IAuthenticationService; ITransactionManagerService: ITransactionManagerService;