Dependency Injection in a Nutshell

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
dependency injection in one sentence was perfectly described by james shore it means giving an object its instance variables but because i know that you are still confused let's take a closer look what actually are dependencies here well these are objects a specific class depends on let's take a look at this computer to be able to run properly it needs a processor ram a hard drive and a graphics card so these single components are the computer's dependencies because the computer depends on these components if we think of this computer now as a class in programming we could either create the single components in the computer class or we could create them somewhere else let's take a look what happens if we create them in the computer class this would mean every computer that we create has the same specs and if we change for example the hard drive it will be changed for all computers this is bad dependency injection solves this problem one way of injecting dependencies is via constructor injection so we pass the computer's components as constructor arguments which allows us to give each computer instance different components this is very good for testing as well because we might want to test if a computer runs with an amd graphics card but also if it runs with an nvidia graphics card this way we can decide which graphics card the computer we want to test should have besides constructor injection there are more complex dependency injection libraries that inject the dependencies behind the scenes with these libraries we can usually also decide about the lifetime of our dependencies there is no reason for the graphics card to be active when we just want to do some office work so it doesn't need to take up that unnecessary memory here but for playing a game it is needed so we can say that the graphics card lives as long as the game is open and not during the whole lifetime of our application and that's really everything about it i recommend you apply this concept in one of your projects to fully understand how it works in [Music] practice [Applause] you
Info
Channel: Philipp Lackner
Views: 87,475
Rating: undefined out of 5
Keywords: android, tutorial, philip, philipp, filipp, filip, fillip, fillipp, phillipp, phillip, lackener, leckener, leckner, lackner, kotlin, mobile, dependency injection, di, dagger, hilt, koin, kodein, inject, dependency
Id: yunF2PgJlHU
Channel Id: undefined
Length: 2min 43sec (163 seconds)
Published: Mon Dec 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.