From 98c419a64e7273a1cc48f556da1a2cc63cacc478 Mon Sep 17 00:00:00 2001 From: Dmitry Neverovski Date: Fri, 16 Feb 2024 10:53:49 +0100 Subject: [PATCH] feat: add DiCore abstract class --- src/config/config.di.ts | 3 ++- src/database/database.di.ts | 4 +++- src/middleware/middleware.di.ts | 3 ++- src/modules/auth/auth.di.ts | 4 +++- src/modules/module.di.ts | 4 +++- src/modules/notification/notification.di.ts | 4 +++- src/modules/otp/otp.di.ts | 4 +++- src/modules/platform/platform.di.ts | 4 +++- src/modules/refresh-token/refresh-token.di.ts | 4 +++- src/modules/user/user.di.ts | 4 +++- src/providers/apple/apple.di.ts | 4 +++- src/providers/cache-manager/cache-manager.di.ts | 4 +++- src/providers/email/email.di.ts | 4 +++- src/providers/facebook/facebook.di.ts | 4 +++- src/providers/github/github.di.ts | 4 +++- src/providers/google/google.di.ts | 4 +++- src/providers/provider.di.ts | 4 +++- src/providers/token/token.di.ts | 4 +++- 18 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/config/config.di.ts b/src/config/config.di.ts index d8a4d84..b4f5de1 100644 --- a/src/config/config.di.ts +++ b/src/config/config.di.ts @@ -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'; @@ -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(); diff --git a/src/database/database.di.ts b/src/database/database.di.ts index a6607dc..6535259 100644 --- a/src/database/database.di.ts +++ b/src/database/database.di.ts @@ -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(); } diff --git a/src/middleware/middleware.di.ts b/src/middleware/middleware.di.ts index 3b94dd2..e065fd7 100644 --- a/src/middleware/middleware.di.ts +++ b/src/middleware/middleware.di.ts @@ -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'; @@ -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(); diff --git a/src/modules/auth/auth.di.ts b/src/modules/auth/auth.di.ts index cafc645..e4f2576 100755 --- a/src/modules/auth/auth.di.ts +++ b/src/modules/auth/auth.di.ts @@ -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'; @@ -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(); diff --git a/src/modules/module.di.ts b/src/modules/module.di.ts index 8c3a079..0281ac9 100755 --- a/src/modules/module.di.ts +++ b/src/modules/module.di.ts @@ -1,3 +1,5 @@ +import { DiCore } from '@core/service'; + import { AuthDi } from './auth/auth.di'; import { NotificationDi } from './notification/notification.di'; import { OtpDi } from './otp/otp.di'; @@ -5,7 +7,7 @@ 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(); diff --git a/src/modules/notification/notification.di.ts b/src/modules/notification/notification.di.ts index 7a656ce..b42ee6d 100755 --- a/src/modules/notification/notification.di.ts +++ b/src/modules/notification/notification.di.ts @@ -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(); } diff --git a/src/modules/otp/otp.di.ts b/src/modules/otp/otp.di.ts index 6684c35..a553111 100755 --- a/src/modules/otp/otp.di.ts +++ b/src/modules/otp/otp.di.ts @@ -1,5 +1,7 @@ import { container as Container } from 'tsyringe'; +import { DiCore } from '@core/service'; + import { IOtpCodeRepository, IOtpService, @@ -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(); diff --git a/src/modules/platform/platform.di.ts b/src/modules/platform/platform.di.ts index 9a13bc7..ce10c3b 100755 --- a/src/modules/platform/platform.di.ts +++ b/src/modules/platform/platform.di.ts @@ -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(); diff --git a/src/modules/refresh-token/refresh-token.di.ts b/src/modules/refresh-token/refresh-token.di.ts index 35f7381..7dfbc19 100755 --- a/src/modules/refresh-token/refresh-token.di.ts +++ b/src/modules/refresh-token/refresh-token.di.ts @@ -1,5 +1,7 @@ import { container as Container } from 'tsyringe'; +import { DiCore } from '@core/service'; + import { IRefreshTokenRepository, IRefreshTokenService, @@ -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(); diff --git a/src/modules/user/user.di.ts b/src/modules/user/user.di.ts index e3d5560..b9de96e 100755 --- a/src/modules/user/user.di.ts +++ b/src/modules/user/user.di.ts @@ -1,5 +1,7 @@ import { container as Container } from 'tsyringe'; +import { DiCore } from '@core/service'; + import { IProfileRepository, IUserController, @@ -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(); diff --git a/src/providers/apple/apple.di.ts b/src/providers/apple/apple.di.ts index 1033e7b..053e8b7 100755 --- a/src/providers/apple/apple.di.ts +++ b/src/providers/apple/apple.di.ts @@ -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(); } diff --git a/src/providers/cache-manager/cache-manager.di.ts b/src/providers/cache-manager/cache-manager.di.ts index 108516b..f52240a 100755 --- a/src/providers/cache-manager/cache-manager.di.ts +++ b/src/providers/cache-manager/cache-manager.di.ts @@ -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(); } diff --git a/src/providers/email/email.di.ts b/src/providers/email/email.di.ts index 13afbda..e3af297 100755 --- a/src/providers/email/email.di.ts +++ b/src/providers/email/email.di.ts @@ -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 { @@ -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(); diff --git a/src/providers/facebook/facebook.di.ts b/src/providers/facebook/facebook.di.ts index c2de247..0427702 100755 --- a/src/providers/facebook/facebook.di.ts +++ b/src/providers/facebook/facebook.di.ts @@ -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(); } diff --git a/src/providers/github/github.di.ts b/src/providers/github/github.di.ts index 51b31ac..df4447b 100755 --- a/src/providers/github/github.di.ts +++ b/src/providers/github/github.di.ts @@ -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(); } diff --git a/src/providers/google/google.di.ts b/src/providers/google/google.di.ts index ac4e178..db94421 100755 --- a/src/providers/google/google.di.ts +++ b/src/providers/google/google.di.ts @@ -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(); } diff --git a/src/providers/provider.di.ts b/src/providers/provider.di.ts index 1466206..5e4698d 100755 --- a/src/providers/provider.di.ts +++ b/src/providers/provider.di.ts @@ -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'; @@ -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(); diff --git a/src/providers/token/token.di.ts b/src/providers/token/token.di.ts index 8e47bf5..97f5f95 100644 --- a/src/providers/token/token.di.ts +++ b/src/providers/token/token.di.ts @@ -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(); }