Angular 8: Get instance of service to another service without using constructor

Namratha T Setty 1 Reputation point
2020-11-13T06:00:31.33+00:00

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

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,810 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.