Skip to content

Commit

Permalink
refactoring dependency injection to arrays instead of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolovlazar committed Oct 30, 2024
1 parent 62276da commit e5b312d
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 184 deletions.
26 changes: 13 additions & 13 deletions di/modules/authentication.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ export function registerAuthenticationModule(container: Container) {

container
.bind(DI_SYMBOLS.ISignInController)
.toHigherOrderFunction(signInController, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
signInUseCase: DI_SYMBOLS.ISignInUseCase,
});
.toHigherOrderFunction(signInController, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.ISignInUseCase,
]);

container
.bind(DI_SYMBOLS.ISignOutController)
.toHigherOrderFunction(signOutController, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
authenticationService: DI_SYMBOLS.IAuthenticationService,
signOutUseCase: DI_SYMBOLS.ISignOutUseCase,
});
.toHigherOrderFunction(signOutController, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.IAuthenticationService,
DI_SYMBOLS.ISignOutUseCase,
]);

container
.bind(DI_SYMBOLS.ISignUpController)
.toHigherOrderFunction(signUpController, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
signUpUseCase: DI_SYMBOLS.ISignUpUseCase,
});
.toHigherOrderFunction(signUpController, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.ISignUpUseCase,
]);
}
78 changes: 39 additions & 39 deletions di/modules/todos.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,64 +29,64 @@ export function registerTodosModule(container: Container) {

container
.bind(DI_SYMBOLS.ICreateTodoUseCase)
.toHigherOrderFunction(createTodoUseCase, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
todosRepository: DI_SYMBOLS.ITodosRepository,
});
.toHigherOrderFunction(createTodoUseCase, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.ITodosRepository,
]);

container
.bind(DI_SYMBOLS.IDeleteTodoUseCase)
.toHigherOrderFunction(deleteTodoUseCase, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
todosRepository: DI_SYMBOLS.ITodosRepository,
});
.toHigherOrderFunction(deleteTodoUseCase, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.ITodosRepository,
]);

container
.bind(DI_SYMBOLS.IGetTodosForUserUseCase)
.toHigherOrderFunction(getTodosForUserUseCase, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
todosRepository: DI_SYMBOLS.ITodosRepository,
});
.toHigherOrderFunction(getTodosForUserUseCase, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.ITodosRepository,
]);

container
.bind(DI_SYMBOLS.IToggleTodoUseCase)
.toHigherOrderFunction(toggleTodoUseCase, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
todosRepository: DI_SYMBOLS.ITodosRepository,
});
.toHigherOrderFunction(toggleTodoUseCase, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.ITodosRepository,
]);

container
.bind(DI_SYMBOLS.IBulkUpdateController)
.toHigherOrderFunction(bulkUpdateController, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
authenticationService: DI_SYMBOLS.IAuthenticationService,
transactionManagerService: DI_SYMBOLS.ITransactionManagerService,
toggleTodoUseCase: DI_SYMBOLS.IToggleTodoUseCase,
deleteTodoUseCase: DI_SYMBOLS.IDeleteTodoUseCase,
});
.toHigherOrderFunction(bulkUpdateController, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.IAuthenticationService,
DI_SYMBOLS.ITransactionManagerService,
DI_SYMBOLS.IToggleTodoUseCase,
DI_SYMBOLS.IDeleteTodoUseCase,
]);

container
.bind(DI_SYMBOLS.ICreateTodoController)
.toHigherOrderFunction(createTodoController, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
authenticationService: DI_SYMBOLS.IAuthenticationService,
transactionManagerService: DI_SYMBOLS.ITransactionManagerService,
createTodoUseCase: DI_SYMBOLS.ICreateTodoUseCase,
});
.toHigherOrderFunction(createTodoController, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.IAuthenticationService,
DI_SYMBOLS.ITransactionManagerService,
DI_SYMBOLS.ICreateTodoUseCase,
]);

container
.bind(DI_SYMBOLS.IGetTodosForUserController)
.toHigherOrderFunction(getTodosForUserController, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
getTodosForUserUseCase: DI_SYMBOLS.IGetTodosForUserUseCase,
authenticationService: DI_SYMBOLS.IAuthenticationService,
});
.toHigherOrderFunction(getTodosForUserController, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.IGetTodosForUserUseCase,
DI_SYMBOLS.IAuthenticationService,
]);

container
.bind(DI_SYMBOLS.IToggleTodoController)
.toHigherOrderFunction(toggleTodoController, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
toggleTodoUseCase: DI_SYMBOLS.IToggleTodoUseCase,
authenticationService: DI_SYMBOLS.IAuthenticationService,
});
.toHigherOrderFunction(toggleTodoController, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.IToggleTodoUseCase,
DI_SYMBOLS.IAuthenticationService,
]);
}
28 changes: 14 additions & 14 deletions di/modules/users.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ export function registerUsersModule(container: Container) {

container
.bind(DI_SYMBOLS.ISignInUseCase)
.toHigherOrderFunction(signInUseCase, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
authenticationService: DI_SYMBOLS.IAuthenticationService,
usersRepository: DI_SYMBOLS.IUsersRepository,
});
.toHigherOrderFunction(signInUseCase, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.IUsersRepository,
DI_SYMBOLS.IAuthenticationService,
]);

container
.bind(DI_SYMBOLS.ISignOutUseCase)
.toHigherOrderFunction(signOutUseCase, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
authenticationService: DI_SYMBOLS.IAuthenticationService,
});
.toHigherOrderFunction(signOutUseCase, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.IAuthenticationService,
]);

container
.bind(DI_SYMBOLS.ISignUpUseCase)
.toHigherOrderFunction(signUpUseCase, {
instrumentationService: DI_SYMBOLS.IInstrumentationService,
authenticationService: DI_SYMBOLS.IAuthenticationService,
usersRepository: DI_SYMBOLS.IUsersRepository,
});
.toHigherOrderFunction(signUpUseCase, [
DI_SYMBOLS.IInstrumentationService,
DI_SYMBOLS.IAuthenticationService,
DI_SYMBOLS.IUsersRepository,
]);
}
14 changes: 5 additions & 9 deletions src/application/use-cases/auth/sign-in.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import type { IAuthenticationService } from '@/src/application/services/authenti
export type ISignInUseCase = ReturnType<typeof signInUseCase>;

export const signInUseCase =
({
instrumentationService,
usersRepository,
authenticationService,
}: {
instrumentationService: IInstrumentationService;
usersRepository: IUsersRepository;
authenticationService: IAuthenticationService;
}) =>
(
instrumentationService: IInstrumentationService,
usersRepository: IUsersRepository,
authenticationService: IAuthenticationService
) =>
(input: {
username: string;
password: string;
Expand Down
11 changes: 4 additions & 7 deletions src/application/use-cases/auth/sign-out.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import type { IAuthenticationService } from '@/src/application/services/authenti
export type ISignOutUseCase = ReturnType<typeof signOutUseCase>;

export const signOutUseCase =
({
instrumentationService,
authenticationService,
}: {
instrumentationService: IInstrumentationService;
authenticationService: IAuthenticationService;
}) =>
(
instrumentationService: IInstrumentationService,
authenticationService: IAuthenticationService
) =>
(sessionId: string): Promise<{ blankCookie: Cookie }> => {
return instrumentationService.startSpan(
{ name: 'signOut Use Case', op: 'function' },
Expand Down
14 changes: 5 additions & 9 deletions src/application/use-cases/auth/sign-up.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ import { PASSWORD_SALT_ROUNDS } from '@/config';
export type ISignUpUseCase = ReturnType<typeof signUpUseCase>;

export const signUpUseCase =
({
instrumentationService,
authenticationService,
usersRepository,
}: {
instrumentationService: IInstrumentationService;
authenticationService: IAuthenticationService;
usersRepository: IUsersRepository;
}) =>
(
instrumentationService: IInstrumentationService,
authenticationService: IAuthenticationService,
usersRepository: IUsersRepository
) =>
(input: {
username: string;
password: string;
Expand Down
11 changes: 4 additions & 7 deletions src/application/use-cases/todos/create-todo.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import type { ITodosRepository } from '@/src/application/repositories/todos.repo
export type ICreateTodoUseCase = ReturnType<typeof createTodoUseCase>;

export const createTodoUseCase =
({
instrumentationService,
todosRepository,
}: {
instrumentationService: IInstrumentationService;
todosRepository: ITodosRepository;
}) =>
(
instrumentationService: IInstrumentationService,
todosRepository: ITodosRepository
) =>
(
input: {
todo: string;
Expand Down
11 changes: 4 additions & 7 deletions src/application/use-cases/todos/delete-todo.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import type { ITodosRepository } from '@/src/application/repositories/todos.repo
export type IDeleteTodoUseCase = ReturnType<typeof deleteTodoUseCase>;

export const deleteTodoUseCase =
({
instrumentationService,
todosRepository,
}: {
instrumentationService: IInstrumentationService;
todosRepository: ITodosRepository;
}) =>
(
instrumentationService: IInstrumentationService,
todosRepository: ITodosRepository
) =>
(
input: {
todoId: number;
Expand Down
11 changes: 4 additions & 7 deletions src/application/use-cases/todos/get-todos-for-user.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import type { ITodosRepository } from '@/src/application/repositories/todos.repo
export type IGetTodosForUserUseCase = ReturnType<typeof getTodosForUserUseCase>;

export const getTodosForUserUseCase =
({
instrumentationService,
todosRepository,
}: {
instrumentationService: IInstrumentationService;
todosRepository: ITodosRepository;
}) =>
(
instrumentationService: IInstrumentationService,
todosRepository: ITodosRepository
) =>
(userId: string): Promise<Todo[]> => {
return instrumentationService.startSpan(
{ name: 'getTodosForUser UseCase', op: 'function' },
Expand Down
11 changes: 4 additions & 7 deletions src/application/use-cases/todos/toggle-todo.use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import type { ITodosRepository } from '@/src/application/repositories/todos.repo
export type IToggleTodoUseCase = ReturnType<typeof toggleTodoUseCase>;

export const toggleTodoUseCase =
({
instrumentationService,
todosRepository,
}: {
instrumentationService: IInstrumentationService;
todosRepository: ITodosRepository;
}) =>
(
instrumentationService: IInstrumentationService,
todosRepository: ITodosRepository
) =>
(
input: {
todoId: number;
Expand Down
11 changes: 4 additions & 7 deletions src/interface-adapters/controllers/auth/sign-in.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ const inputSchema = z.object({
export type ISignInController = ReturnType<typeof signInController>;

export const signInController =
({
instrumentationService,
signInUseCase,
}: {
instrumentationService: IInstrumentationService;
signInUseCase: ISignInUseCase;
}) =>
(
instrumentationService: IInstrumentationService,
signInUseCase: ISignInUseCase
) =>
async (input: Partial<z.infer<typeof inputSchema>>): Promise<Cookie> => {
return await instrumentationService.startSpan(
{ name: 'signIn Controller' },
Expand Down
14 changes: 5 additions & 9 deletions src/interface-adapters/controllers/auth/sign-out.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import { IAuthenticationService } from '@/src/application/services/authenticatio
export type ISignOutController = ReturnType<typeof signOutController>;

export const signOutController =
({
instrumentationService,
authenticationService,
signOutUseCase,
}: {
instrumentationService: IInstrumentationService;
authenticationService: IAuthenticationService;
signOutUseCase: ISignOutUseCase;
}) =>
(
instrumentationService: IInstrumentationService,
authenticationService: IAuthenticationService,
signOutUseCase: ISignOutUseCase
) =>
async (sessionId: string | undefined): Promise<Cookie> => {
return await instrumentationService.startSpan(
{ name: 'signOut Controller' },
Expand Down
11 changes: 4 additions & 7 deletions src/interface-adapters/controllers/auth/sign-up.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ const inputSchema = z
export type ISignUpController = ReturnType<typeof signUpController>;

export const signUpController =
({
instrumentationService,
signUpUseCase,
}: {
instrumentationService: IInstrumentationService;
signUpUseCase: ISignUpUseCase;
}) =>
(
instrumentationService: IInstrumentationService,
signUpUseCase: ISignUpUseCase
) =>
async (
input: Partial<z.infer<typeof inputSchema>>
): Promise<ReturnType<typeof signUpUseCase>> => {
Expand Down
20 changes: 7 additions & 13 deletions src/interface-adapters/controllers/todos/bulk-update.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@ const inputSchema = z.object({
export type IBulkUpdateController = ReturnType<typeof bulkUpdateController>;

export const bulkUpdateController =
({
instrumentationService,
authenticationService,
transactionManagerService,
toggleTodoUseCase,
deleteTodoUseCase,
}: {
instrumentationService: IInstrumentationService;
authenticationService: IAuthenticationService;
transactionManagerService: ITransactionManagerService;
toggleTodoUseCase: IToggleTodoUseCase;
deleteTodoUseCase: IDeleteTodoUseCase;
}) =>
(
instrumentationService: IInstrumentationService,
authenticationService: IAuthenticationService,
transactionManagerService: ITransactionManagerService,
toggleTodoUseCase: IToggleTodoUseCase,
deleteTodoUseCase: IDeleteTodoUseCase
) =>
async (
input: z.infer<typeof inputSchema>,
sessionId: string | undefined
Expand Down
Loading

0 comments on commit e5b312d

Please sign in to comment.