Skip to content

Plugin dependency injection #1

@jano42

Description

@jano42

Is there a way to inject in a plugin constructor, a class provided by core-app ?

In fact I would like:

Have an abstract class

export declare abstract class IPluginComponent {
    abstract methodDeclaredInCoreApp(first: String, last: String): String;
    abstract anotherMethod(): any;
}

My plugin component which use the interface

constructor(private srvInterface: IPluginComponent) { }

  public onSubmit() {
        this.result = this.srvInterface.methodDeclaredInCoreApp(this.first, this.last);
  }

And in the coreApp realize the IPluginComponent implementation

export class PluginInterface implements IPluginComponent {
    methodDeclaredInCoreApp(first: String, last: String): String {
        return first + ' @ ' + last;
    }    
    
    anotherMethod(): any {
        return 42;
    }    

}

Finally I've make some tries but it fails at runtime on

// compile module
const moduleFactory = await this._compiler.compileModuleAsync<any>(module["PluginAModule"]);

My console error :
Error: Can't resolve all parameters for PluginAComponent: (?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions