Skip to content

Instantly share code, notes, and snippets.

@debugmodedotnet
Created October 17, 2020 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debugmodedotnet/fcaaf5aec02844365ff26a83cba289df to your computer and use it in GitHub Desktop.
Save debugmodedotnet/fcaaf5aec02844365ff26a83cba289df to your computer and use it in GitHub Desktop.
Title: Simplifying Dependency Injection in Angular
Dependency Injection is one of the most famous architecture patterns to create a scalable application that has loosely coupled entities such as classes. Application made using the DI pattern is highly loosely coupled, and any part such as the business logic layer of application can be replaced at the run time without affecting the presentation layer. By design Angular framework supports dependency injection. It enables you to inject dependencies such as services without writing your own DI container or refereeing to any third-party libraries.
You create a service in Angular to share data and operations between components, directives etc. Mainly services are used to achieve separation of concerns and reusability. You keep operations such as API calls, logging, client-side data manipulations, etc. in a service. One of the significant purposes of creating service is to keep component clean that focuses on user interaction and presentations.
So, if you create an object of services directly inside a component, then components and services are tightly coupled, and so Angular by design avoids that.
In this deep dive talk, you will learn about DI in Angular. This talk will cover in detail the various level of Providers and Injectors. You will learn,
1. How to create a tree-shakeable singleton service
2. Inject a service in lazy-loaded modules
3. Various providers such as
a. useClass
b. useExisting
c. useFactory
d. useValue
4. What are the best practices to work with Injector hierarchy etc.
This talk is a live coding talk with no PPT. The biggest take away from the talk would be, how to use Angular inbuilt DI to create better performant Angular application.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment