Skip to content

Commit

Permalink
feat: add DiCore abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
neverovski committed Feb 16, 2024
1 parent 27a44ad commit 98c419a
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/config/config.di.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { container as Container } from 'tsyringe';

import { ConfigKey } from '@common/enums';
import { DiCore } from '@core/service';

import { AppConfig } from './app.config';
import { DatabaseConfig } from './database.config';
Expand All @@ -19,7 +20,7 @@ import { LoggerConfig } from './logger.config';
import { PlatformConfig } from './platform.config';
import { RedisConfig } from './redis.config';

class ConfigDi {
class ConfigDi extends DiCore {
register() {
this.registerApp();
this.registerDatabase();
Expand Down
4 changes: 3 additions & 1 deletion src/database/database.di.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { DatabaseInject } from './database.enum';
import { DatabaseService } from './database.service';
import { IDatabaseService } from './interface';

class DatabaseDi {
class DatabaseDi extends DiCore {
register() {
this.registerService();
}
Expand Down
3 changes: 2 additions & 1 deletion src/middleware/middleware.di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { container as Container } from 'tsyringe';

import { MiddlewareKey } from '@common/enums/middleware.enum';
import { IMiddleware } from '@common/interfaces';
import { DiCore } from '@core/service';

import { AsyncMiddleware } from './async.middleware';
import { AuthMiddleware } from './auth.middleware';
Expand All @@ -12,7 +13,7 @@ import { PrometheusMiddleware } from './prometheus.middleware';
import { UserSessionMiddleware } from './user-session.middleware';
import { ValidateMiddleware } from './validate.middleware';

class MiddlewareDi {
class MiddlewareDi extends DiCore {
register() {
this.registerAsync();
this.registerAuth();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/auth/auth.di.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { AuthController } from './auth.controller';
import { AuthInject } from './auth.enum';
import { AuthSchema } from './auth.schema';
Expand All @@ -11,7 +13,7 @@ import {
} from './interface';
import { AuthService, AuthTokenService } from './service';

export class AuthDi {
export class AuthDi extends DiCore {
register() {
this.registerTokenService();
this.registerService();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/module.di.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { DiCore } from '@core/service';

import { AuthDi } from './auth/auth.di';
import { NotificationDi } from './notification/notification.di';
import { OtpDi } from './otp/otp.di';
import { PlatformDi } from './platform/platform.di';
import { RefreshTokenDi } from './refresh-token/refresh-token.di';
import { UserDi } from './user/user.di';

class ModuleDi {
class ModuleDi extends DiCore {
register() {
new NotificationDi().register();
new OtpDi().register();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/notification/notification.di.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { INotificationService } from './interface';
import { NotificationInject } from './notification.enum';
import { NotificationService } from './notification.service';

export class NotificationDi {
export class NotificationDi extends DiCore {
register() {
this.registerService();
}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/otp/otp.di.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import {
IOtpCodeRepository,
IOtpService,
Expand All @@ -9,7 +11,7 @@ import { OtpInject } from './otp.enum';
import { OtpCodeRepository } from './repository';
import { OtpService, OtpValidatorService } from './service';

export class OtpDi {
export class OtpDi extends DiCore {
register() {
this.registerRepository();
this.registerService();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/platform/platform.di.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { IPlatformRepository, IPlatformService } from './interface';
import { PlatformInject } from './platform.enum';
import { PlatformService } from './platform.service';
import { PlatformRepository } from './repository';

export class PlatformDi {
export class PlatformDi extends DiCore {
register() {
this.registerRepository();
this.registerService();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/refresh-token/refresh-token.di.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import {
IRefreshTokenRepository,
IRefreshTokenService,
Expand All @@ -9,7 +11,7 @@ import { RefreshTokenInject } from './refresh-token.enum';
import { RefreshTokenRepository } from './repository';
import { RefreshTokenService, RefreshTokenValidatorService } from './service';

export class RefreshTokenDi {
export class RefreshTokenDi extends DiCore {
register() {
this.registerRepository();
this.registerValidatorService();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/user/user.di.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import {
IProfileRepository,
IUserController,
Expand All @@ -15,7 +17,7 @@ import { UserController } from './user.controller';
import { UserInject } from './user.enum';
import { UserSchema } from './user.schema';

export class UserDi {
export class UserDi extends DiCore {
register() {
this.registerRepositoryProfile();
this.registerRepository();
Expand Down
4 changes: 3 additions & 1 deletion src/providers/apple/apple.di.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { AppleInject } from './apple.enum';
import { AppleService } from './apple.service';
import { IAppleService } from './interface';

export class AppleDi {
export class AppleDi extends DiCore {
register() {
this.registerService();
}
Expand Down
4 changes: 3 additions & 1 deletion src/providers/cache-manager/cache-manager.di.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { CacheManagerInject } from './cache-manager.enum';
import { CacheManagerService } from './cache-manager.service';
import { ICacheManagerService } from './interface';

export class CacheManagerDi {
export class CacheManagerDi extends DiCore {
register() {
this.registerService();
}
Expand Down
4 changes: 3 additions & 1 deletion src/providers/email/email.di.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { EmailInject } from './email.enum';
import { EmailService } from './email.service';
import {
Expand All @@ -9,7 +11,7 @@ import {
} from './interface';
import { EmailConsumerJob, EmailProducerJob } from './job';

export class EmailDi {
export class EmailDi extends DiCore {
register() {
this.registerService();
this.registerProducer();
Expand Down
4 changes: 3 additions & 1 deletion src/providers/facebook/facebook.di.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { FacebookInject } from './facebook.enum';
import { FacebookService } from './facebook.service';
import { IFacebookService } from './interface';

export class FacebookDi {
export class FacebookDi extends DiCore {
register() {
this.registerService();
}
Expand Down
4 changes: 3 additions & 1 deletion src/providers/github/github.di.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { GitHubInject } from './github.enum';
import { GitHubService } from './github.service';
import { IGitHubService } from './interface';

export class GitHubDi {
export class GitHubDi extends DiCore {
register() {
this.registerService();
}
Expand Down
4 changes: 3 additions & 1 deletion src/providers/google/google.di.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { GoogleInject } from './google.enum';
import { GoogleService } from './google.service';
import { IGoogleService } from './interface';

export class GoogleDi {
export class GoogleDi extends DiCore {
register() {
this.registerService();
}
Expand Down
4 changes: 3 additions & 1 deletion src/providers/provider.di.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DiCore } from '@core/service';

import { AppleDi } from './apple/apple.di';
import { CacheManagerDi } from './cache-manager/cache-manager.di';
import { EmailDi } from './email/email.di';
Expand All @@ -7,7 +9,7 @@ import { GoogleDi } from './google/google.di';
import { LoggerDi } from './logger/logger.di';
import { TokenDi } from './token/token.di';

class ProviderDi {
class ProviderDi extends DiCore {
register() {
new LoggerDi().register();
new TokenDi().register();
Expand Down
4 changes: 3 additions & 1 deletion src/providers/token/token.di.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { container as Container } from 'tsyringe';

import { DiCore } from '@core/service';

import { ITokenService } from './interface';
import { TokenInject } from './token.enum';
import { TokenService } from './token.service';

export class TokenDi {
export class TokenDi extends DiCore {
register() {
this.registerService();
}
Expand Down

0 comments on commit 98c419a

Please sign in to comment.