Its fairly simply:
Inside my generic CrudController I have a property:
someProp = "someData"
or actually constructor(someProp: string, crudService: CrudService){}
on a POST route for that Controller I add an interceptor like so:
@UseInterceptors(createInterceptor(this.someProp)) findMany(@Body() args: FindManyArgs) { return this.crudService.findMany(args); }
The createInterceptor
function is simply a factory function which creates an Instance of an Interceptor – should be irrelevant here.
Relevant is, that I cannot pass “this.someProp” cause in the context of a decorator there is no “this”. In the IDE it says that this is “possibly undefined” (which it actually is). I can easily pass the data directly as a string or object or whatever inside the decorator, but the thing is that myProperty comes from the constructor and is set by whoever instanciates the controller since it’a more generic one.
Any suggestions?
I feel like the Decorators are converted to something that is executed before instantiation of the Interceptor, but if so, then how can i dynamically pass data to the Interceptor? Its not an option to inject a service into the Interceptor because it is not one specific service but rather a concrete implementation of an abstract one thats
Johannes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.