Introducing Angular Service Injection with the Dependency Injector

Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 8 months ago

Hi, here's a short intro to my course about Angular Services and how they use the Dependency Injector in Angular.

The goal of this Angular Service Injection with the Dependency Injector course is to learn about the various ways Angular services can be created and provided with the dependency injector. While dependency injection has a broader range of applications, in this course we will mostly focus on the Angular services part and how they make use of DI.

That includes learning what a service is about, how it can be registered with the DI mechanism. We will learn about service aliases, value providers and factory functions. Also, understanding the lifetime of a service instance and how to control it, can be fundamental for creating some more advanced Angular apps. That's also when we learn about the hierarchical nature of Angular's DI. Towards the end we'll take a look at what Angular provider shadowing is all about, and how it can cause some headache when not applied properly.

Enjoy the course!

Instructor: [00:00] The goal of this Angular service injection with the dependency injector course is to learn about the various ways Angular services can be created and provided with the dependency injector. If you think about dependency injection as being a very core part of Angular/Jest version one already, and it's actually still a fundamental element in Angular today.

[00:16] While dependency injection in general has a broader range of applications within Angular, in this course, we will mostly focus on the Angular service part, and how they make use of the dependency injection.

[00:27] First of all, we will walk through very simple standalone examples. We'll be learning about what a service is about, how we can define one, and why we need dependency injection in the first place. We will about concepts such as service aliases and value providers, highlighting some use cases for those as well.

[00:43] We obviously also create an Angular factory provider. We will learn how to pass dependencies into such a factory function and get to know why such factory functions can actually be a lifesaver in certain situations.

[00:55] In general, services by themselves are singletons, meaning we only have one instance per application. There are mechanisms, however, how we can control lifetime of a service, as well as the number of instance we want to have.

[01:08] That's also why we will get first into conduct with the hierarchical nature of Angular's dependency injector. Towards the end of the course, we will take a look at more advanced topics. For instance, we will see how these loaded modules together with shared services can cause you quite some headache, which is also known an Angular provider shadowing.

[01:26] We will learn about how to circumvent and overcome such side effects, and how to implement best practices. Finally, we will also take a look at how to apply some more fine-grain control over the dependency injector.

[01:39] I'm actually very excited about this course because it teaches you from the very basics to the more advanced topics of Angular services and dependency injection, something you definitely need on a daily basis within your Angular apps.

egghead
egghead
~ 32 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today