1.1.0 • Published 3 years ago

@angular-ru/autowired v1.1.0

Weekly downloads
6
License
MIT
Repository
-
Last release
3 years ago

Simple Dependency Injection with BeanAccessible

$ npm install --save-dev @angular-ru/autowired

The decorator @Autowired tells the Angular application that the class it is underlined is a service, that is, a candidate for automatic detection (DI).

Before

app.module.ts

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [ServiceA, ServiceB, ServiceC, ServiceD],
  bootstrap: [AppComponent]
})
export class AppModule { }

base.component.ts

export class BaseComponent {
 constructor(
    private c: ServiceC, 
    private d: ServiceD
 ) {}
 
 ...
}

app.component.ts

export class AppComponent extends BaseComponent {
 constructor(
    private a: ServiceC, 
    private b: ServiceD, 
    private c: ServiceC, 
    private d: ServiceD
 ) {
   super(c, d);
 }
 
 ...
}

After

app.module.ts

@NgModule({
  declarations: [AppComponent],
  imports: [
     BrowserModule,
     BeanAccessibleModule.forRoot()
  ],
  providers: [ServiceA, ServiceB, ServiceC, ServiceD],
  bootstrap: [AppComponent]
})
export class AppModule { }

base.component.ts

export class BaseComponent {
 @Autowired() private c: ServiceC;
 @Autowired() private d: ServiceD;
 
 ...
}

app.component.ts

export class AppComponent extends BaseComponent {
 @Autowired() private a: ServiceA;
 @Autowired() private b: ServiceB;
 
 ...
}

Decorator @Autowired

The decorator @Autowired tells the Angular application that the class it is underlined is a service, that is, a candidate for automatic detection (DI).

1.1.0

3 years ago

1.0.0

3 years ago