GithubHelp home page GithubHelp logo

autowired's Introduction

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;

 ...
}

autowired's People

Contributors

dependabot[bot] avatar splincode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

levart

autowired's Issues

BeanAccessibleModule not exported

Hi,
I encounter this error when I launch my angular application. I am at version 9 of angular.

ERROR in src/app/shared/shared.module.ts:47:9 - error TS2305: Module '"D:/angular-starter-template/node_modules/@angular-ru/autowired/angular-ru-autowired"' has no exported member 'BeanAccessibleModule'.

47 import {BeanAccessibleModule} from '@angular-ru/autowired';

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.