cichy380 / my-repositories

List of my GitHub repositories. Implementation of Dependency Inversion Principle in Angular.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dependency Inversion Principle (DIP)

Depend upon Abstractions. Do not depend upon concretions.

Example in Angular

This project was generated with Angular CLI version 13.0.3.

Abstraction

The RepositoryService is abstraction layer for getting the collection of repositories.

@Injectable()
abstract class RepositoryService {
  abstract getRepositories(ownerLogin: string): Observable<IRepository[]>
}

Injection

In the AppController we inject service that is hidden by the RepositoryService injection token.

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent {
  constructor(private repositoryService: RepositoryService) {
  }
}

Provider

The GithubInfrastructureModule says that in that place, it should be provided a GithubRepositoryService class.

@NgModule({
  providers: [
    { provide: RepositoryService, useClass: GithubRepositoryService },
  ],
  imports: [
    CommonModule,
  ],
})
export class GithubInfrastructureModule { }

Inspiration and source

Article by Maciej Sikorski

https://betterprogramming.pub/how-to-follow-the-dependency-inversion-principle-in-nestjs-and-angular-8d344303dc3b

Polish version: https://www.angular.love/2020/12/02/jak-postepowac-zgodnie-z-zasada-odwrocenia-zaleznosci-dip-w-nestjs-i-angular/

Development

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

About

List of my GitHub repositories. Implementation of Dependency Inversion Principle in Angular.

License:MIT License


Languages

Language:TypeScript 82.3%Language:JavaScript 13.1%Language:HTML 3.9%Language:SCSS 0.7%