Skip to content

Commit

Permalink
renaming DI and DI_TYPES like previously named DI_SYMBOLS and DI_RETU…
Browse files Browse the repository at this point in the history
…RN_TYPES
  • Loading branch information
nikolovlazar committed Oct 30, 2024
1 parent 10c1e44 commit 23114fe
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 86 deletions.
8 changes: 5 additions & 3 deletions di/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -15,6 +15,8 @@ registerAuthenticationModule(container);
registerUsersModule(container);
registerTodosModule(container);

export function getInjection<T extends keyof DI_TYPES>(key: T): DI_TYPES[T] {
return container.get<DI_TYPES[T]>(DI[key]);
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]);
}
40 changes: 22 additions & 18 deletions di/modules/authentication.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
6 changes: 3 additions & 3 deletions di/modules/database.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
16 changes: 11 additions & 5 deletions di/modules/monitoring.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
72 changes: 36 additions & 36 deletions di/modules/todos.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
44 changes: 25 additions & 19 deletions di/modules/users.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
4 changes: 2 additions & 2 deletions di/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 23114fe

Please sign in to comment.