I am trying to create a new instance without breaking the DI layer, allowing my instance to have access to all injectable services it is using in its constructor
n example of what I have currently which does not allow me using any injectable services:
const camera: Camera = new Camera(id, options);
With this approach, the camera class could not import any injectable singletons or classes.
I have read here that you can use moduleRef
to create a new instance, so I tried the following:
const camera: Camera = await this.moduleRef.create(Camera);
But the issue now is, I can't pass the ID
and Options
parameters, the only solution would be using a setter right after initializing it.
Question:
How can you create a new instance (not singleton) of a class, have it created by nest's injector and pass custom parameters on creation in the latest version of NestJS?