In order to Inject a provider the component has to belong to a context (Basically a module) in the nest application, basically it has to be or a Injectable, Controller, Async Provider or a Custom Async Provider, and it has to belong to a Module in which it has access to the provider you are trying to inject. In order to use a functionality of a service in external javascript classes that are not in a context you can import the service and you gotta instantiate it by yourself here you can have an example of this aproach:
class SampleClass {
private memberService: MemberService;
constructor() {
this.memberService = new MemberService();
}
}
Remember this is another instance of the service and if you don't take care you will have multiple instances on runtime as it is not an injectable anymore but a class object. In order to prevent this maybe you can create a singleton containing all the MemberService functionality and import it in both the MemberService and the SampleClass:
export class MemberFunctionality {
private static memberFunctionality: MemberFunctionality;
private constructor() {}
static getInstance(): MemberFunctionality {
if(!memberFunctionality) {
this.memberFunctionality = new MemberFunctionality();
}
return this.memberFunctionality;
}
login() {}
}
Then you import it on both MemberService and SampleClass and call the getInstance method
import { MemberFunctionality } from './member-functionality.ts';
class SampleClass {
private memberFunctionality: MemberFunctionality;
constructor() {
this.memberFunctionality = MemberFunctionality.getInstance();
}
...
}
same goes for the MemberService
import { MemberFunctionality } from './member-functionality.ts';
@Injectable()
export class MemberService {
private memberFunctionality: MemberFunctionality;
constructor(@Inject(Constants.RelationshipMemberModel) private readonly relationshipMemberModel: typeof Model) {
this.memberFunctionality = MemberFunctionality.getInstance();
}
login () {
return this.memberFunctionality.login();
}
}
And that would take care of only having an instance of that functionality