Depend upon Abstractions. Do not depend upon concretions.
This project was generated with Angular CLI version 13.0.3.
The RepositoryService
is abstraction layer for getting the collection of repositories.
@Injectable()
abstract class RepositoryService {
abstract getRepositories(ownerLogin: string): Observable<IRepository[]>
}
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) {
}
}
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 { }
Article by Maciej Sikorski
Polish version: https://www.angular.love/2020/12/02/jak-postepowac-zgodnie-z-zasada-odwrocenia-zaleznosci-dip-w-nestjs-i-angular/
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.