Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AngularJS Services and Dependencies What is Dependency Injection?

Stephen Poole
Stephen Poole
9,361 Points

Is a dependancy exactly the same thing as a service?

Is a dependancy exactly the same thing as a service?

1 Answer

Service can be a dependency but dependency is not necessarily or limited to a service.

Dependency injection is a concept. It simply means passing objects to a method/function as parameters instead of instantiate/initialize objects in the method/function. In our case, the object is the service.

The advantage of doing this is the separation of responsibility. It passes the responsibility of initialization to the caller of the method/function. It makes the code more modular and increase maintainability and readability.

Stephen Poole
Stephen Poole
9,361 Points

Thank you Chi! Awesome answer, clears it right up!