Aurelia1 `@newInstance` with dynamic dependency from container

Hi there,

I have a class where I have 2 constructor parameters: TaskQueue and a boolean.

class ValidationService {
    constructor(private _taskQueue: TaskQueue, private _ignoreHidden = true) {
    }
}

I can use @newInstance attribute to tell to a current dependency injection container to create a new instance, by providing explicitly instantiated “dynamic arguments”: new TaskQueue() and false.

@autoinject()
class MyComponent {
    constructor(@newInstance(ValidationService, new TaskQueue() , false){
   }
}

Is it possible to tell to the @newInstance decorator to use TaskQueue instance from dependency injection container? Something like:

@autoinject()
class MyComponent {
    constructor(@newInstance(ValidationService, @resolve\FromContainer(TaskQueue) tq , false){
   }
}

Thank you,
Nenad

Constructing instances with both statically declared dependencies and dynamically supplied dependencies can be done via factory. An example is here Dumber Gist

1 Like