Reputation: 11
I am using microsoft adaptive card 2.0. I need to create some action service and pass that service to adaptive card module and from there it will execute. But while implementing I am facing issue. That action service has dependency on other services and we cant pass that dependencies from constructor.
**ActionService.js**
import ServiceX from '../'
import ServiceZ from '../'
export Class ActionService{
constructor(
private serviceX: ServiceX,
private serviceZ: ServiceZ
)
execute(){
this.serviceX.action()
}
}
**AdaptiveCard service**
import { ActionService } from '../'
import * as AC from 'adaptivecards';
export class AdaptiveCardService{
AC.GlobalRegistry.actions.register('name-of-action', ActionService);
}
Here the problem is, from adaptive module calling Action service using NEW keyword and not passing dependencies as arguments. Hence in action service inside execute function, servicex getting undefined.
Is there any way to inject services without calling in constructor .
I referred below url to inject it but it is supported only in Angular 2
Getting instance of service without constructor injection
Upvotes: 1
Views: 1074
Reputation: 39
You can use Injector
.
constructor(private injector: Injector) {
let serviceX: ServiceX= this.injector.get(ServiceX);
}
For information Angular Injector
Upvotes: 1