Hi there,
I would love to have some help injecting the cache manager to my custom service from my module class.
Here is the code I currently have:
@Module({
imports: [
CacheModule.registerAsync({
isGlobal: true,
}),
],
providers: [CustomService],
exports: [CustomService],
})
export class CustomModule {
public static registerAsync(options: CustomOptions): DynamicModule {
const provider: Provider = {
provide: CustomService,
useFactory: (
options: CustomOptions,
cacheManager: Cache,
httpService: HttpService
) => new CustomService(cacheManager, httpService),
inject: [CACHE_MANAGER, HttpService],
};
return {
global: true,
module: CustomModule,
imports: [...(options.imports ?? [])],
providers: [provider],
exports: [provider],
};
}
}
@Injectable()
export class CustomService {
constructor(
@Inject(CACHE_MANAGER) private cacheManager: Cache,
private readonly httpService: HttpService
) {}
}
However by doing that I've got the next error message:
Nest cannot export a provider/module that is not a part of the currently processed module (CustomModule). Please verify whether the exported CACHE_MANAGER is available in this particular context.
Possible Solutions:
- Is CACHE_MANAGER part of the relevant providers/imports within CustomModule?
Hope you can help me figured out this issue 😉