#[SOLVED] dynamic module and relation between providers

2 messages · Page 1 of 1 (latest)

sharp hatch
#

Hi everyone, I think I'm making an anti-pattern on this code:

@Global()
@Module({})
export class DynamicConnectionModule {
    static register(
        providers: {
            ConnectionService: ClassProvider<ConnectionService>["useClass"]
            TokenInterceptor?: ClassProvider<TokenInterceptor>["useClass"]
        },
        imports: DynamicModule[]
    ): DynamicModule {
        const currentProviders: Provider[] = [
            {
                provide: ConnectionService,
                useClass: providers.ConnectionService,
            },
            {
                provide: CTX_GQL_CLIENT,
                useFactory: async (connectionService: ConnectionService): Promise<Client> =>
                    connectionService.getShopifyAdminGraphqlClient(),
                scope: Scope.REQUEST,
                inject: [ConnectionService],
            },
        ]
        if (providers.TokenInterceptor) {
            currentProviders.push({
                provide: APP_INTERCEPTOR,
                useClass: providers.TokenInterceptor,
            })
        }
        return {
            global: true,
            module: DynamicConnectionModule,
            imports,
            providers: currentProviders,
            exports: [CTX_GQL_CLIENT, ConnectionService],
        }
    }
}

Is there a way for my CTX_GQL_CLIENT to be dependant to the current instantiated ConnectionService ?

Edit: I'm dumb it works!

#

[SOLVED] dynamic module and relation between providers