1

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

Namratha
  • 11
  • 1

1 Answers1

1

You can use Injector.

constructor(private injector: Injector) {
        let serviceX: ServiceX= this.injector.get(ServiceX);
}

For information Angular Injector

HKR
  • 39
  • 3
  • I tried this and it didn't work as the problem here is: For registering the adaptive cards actions, we should pass a service without any parameters. i.e, Inside Adaptivecardservice, we should be able to pass ActionService without any parameters. export class AdaptiveCardService{ AC.GlobalRegistry.actions.register('name-of-action', ActionService); } – Namratha Nov 13 '20 at 20:06