What is dependency injection in spring [ Getting started ] | Spring framework tutorial for beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back so in this video we'll be talking about springs dependency injection concept so before we get started with coding this video will provide you and high-level overview on dependency injection and as we go further with this course we're going to learn a lot of things about dependency injection but let's first get started ok let's first understand what is dependency injection it's not a very high-level concept it's a very simple concept and let's make it more simple by by some pictures by some animations and by a presentation so let's get started and let's understand the story the concept of dependency injection in a broad way ok so to make you understand this first you forget about Java okay think think very simply think about this guy okay so this guy is so happy let's say this guy's me okay so I'm so happy so why I'm so happy because all my dependencies are fulfilled so what could be a dependency dependency is something that I depend upon if that's that's fulfilled if there's dependency is satisfied then I'm happy right so let's say this guy has some dependency and the first dependency that I do have is my family if they are happy I'm happy obviously my family is my dependency if I want to be happy if I want to sustain in this world without any worries then make sure that my family is happy right just like you all right so my family is one of the dependency that I do have okay so the next dependency to be happy so I should have is my job okay so if I have a job then I'll have some put right obviously if I have a job I'll get some money from that money I'll care some food and I'll have this food then I'll be alive then I can make some free videos for you guys then can help you to understand dependency injection in a simpler way right so my job is one of the dependency that I do have okay because my job provides me money okay okay another thing okay I have a job I got some money right then I can purchase a bike or a car right but even if I do have a car even if I do have a bike I cannot try why I cannot write because if I don't have this I cannot at all drive okay otherwise the cops they are going to catch me and they're going to put me in the jail right so dude to drive a bike or to drive a car I need to make sure that I should have the driving license and that is one of the dependency that I do have because you know what to drive a bike to drive a car I need this driving lessons right okay so now I do have a driving licence okay but I cannot go to my hometown by driving a car my hometown is so far from here the place I'm staying so I need to fly I need to catch a flight and to go by a flight I need my passport okay so if I want to go to my hometown I need to make sure that I should have my passport ready right and this passport is one of the dependency that I do have right because to fly I need a passport right and just like that I should have my fun card I should have my other card I should have my election ID card I should have my all government ID ready to to ever the features though the facilities that my government is providing and to prove that I am a citizen of India I need all these cars with me right so these cars are all so few of the dependency that I do have so this all are my dependencies right I depend upon all these things right okay so now because I'm understanding about dependencies right dependencies is something that I depend upon right and on top of all these things I should have something to sustain here okay okay so don't think very logically you know just think about I should have a name right obviously if I have a name you can tell me here will I say do this hey do that okay do this work for me you can call me by my name right some I should have a name right obviously I should have a name so my name is also one of my dependencies right if I'm here in this world I should have a name right I'm a human object right so and the next thing I should have is my home number I - I should stay somewhere right I should remember that okay this is the place that I'm staying right so this is the home that I'm staying here and this is the number of this home right so I should remember the name of the home the number of the home right so my home number is also one of the dependency because that's the place that's where I stay and I should remember that right so let's go with this right now I'm not going to bore you anymore okay just think like this all other dependency that I do have if I want to leave here to leave if I want to sustain in this world then I should have all these things ready so these all are my dependencies right so you almost got what dependence index and means now let's go to the next slide and let's talk about Java for a bit now come back to Java right I'm not going to tell you any more story over here and now you just think about Java okay in Java when we talk about you know whatever we talked about in Java they all are objects right so we're from the objects are coming from the objects are coming from classes right so now let's treat this guy this this you know this this happy looking guy to alert let me convert this guy to a class right so this is me right so let me convert this guy to a class called class mean okay all right so like that this is my family right so let me convert this picture to the Java class let me say class family right and similarly I do have my job here right so let's treat my job as a class so let's say class job and obviously this what digital are simply numbers right if somebody calls you he'll ask you hey what is your driving license number hey what is a passport number what is your pan number so all these things are numbers right so let me simply say this driving license is a number this passport is a number this fun car is a number some bunch of important numbers right and how to represent a group of numbers in Java if I want to represent a group of numbers a group of entity in Java then I need to take the use of I mean I had to use the collection right I need to I can use collection to store a group of entity a group of numbers right so in this case let me use a collection called I released to store all my important numbers right so let's say I have a bunch of important numbers and I'm storing it using an ArrayList and I met it type step by by making its generic type as integer because I know that whatever the numbers that I'm going to put here with this list this is going to be of integer type these are some bunch of numbers only so I made it of integer type right so that's it so whatever we have seen in the last slide now I have converted everything I mean something which looks familiar to you because it's all in Java right now okay so now I got this thing nickname and home number okay so how can I store a name in Java so if I were to store a name a string in Java then definitely I need to store the name to store the string with the data type called string rice the string is a class in Java so I can I can write string name right because the name I want to store it with string datatype right and similarly if I want to store my home number then I need to store my home number which is a number and I want to store a number in the data type called int right so I'll write int home number simple right so right now I have converted this name and home number I want to store it so I have store it with string and int so this work is done let me remove it all right so this looks good right now now let me have some space here let me increase the space for a bit okay ah this looks good all right okay so now let's say this okay so I I told you right this is me this is my this is me I just just remember that picture right I have a dependency and when one of my dependence is my family right so if I want to be happy if I want to be sustained in this world then I am depend on my family that means inside my class I should have the family object I should have my family object I should right family ethical Danube family right but if you look at the previous two variables that I have declared here I haven't initialized them right so similarly I am NOT going to initialize it I'm going to initialize it later so the new family part I am going to remove it and I am going to put a semicolon all right so this stuff I I just move it to here so this work is done so let me remove it all right so that's done okay similarly I told you if I want to sustain in this world then I need a job right so I do have a class called job here this what I am depends on so let me move this job to here so let me say you know job jaql to new job and you know what I am NOT initializing anything over here as you were saying so let me you know let me not initialize this particular part so let me remove it and put a semicolon over here right so this job I bought it over here and I'm going to remove this one over here because this work is done I have already moved it to my class right okay so one more thing is remaining are a list of important numbers right so that's how a bunch of important numbers that I depends on and this is also one of my dependency so I'm going to move it inside the class and now that thing is also gone so these are some bunch of variables that I do have this variable is of string type this variable is of n type this F is a family type so this family is a class similarly this J is a job type job is a class and this import number is also a class type are a list but we can say this is a type of collection right sorry list is a collection so we understood that this bunch of variables are what okay this is now this is the thing that I'm going to concentrate on this bunch of variables that you are looking at right now these things are called as dependencies right so my class has this number of dependencies right now if you want to make a object of mine make sure all these things all these properties are fulfilled all these properties values are inserted my my I should have a name I should have a home number I should have a family object created I should have a job object created I should insert all my important numbers I should create an array list object I need to do important numbers to add passport number whatever okay I need to initialize these things all right so what I actually talking about is you know if you look at this right now it can it can you know feel better right I'm talking about this initialization you can see the name has a value called a village the home number has a value called 1 2 3 4 5 the family has been initialized I got create a object new family I'm assigning this object to F and similarly new job I'm assigning it to J and you know I have created a new are a list object and using this reference variable important numbers I'm adding a bunch of important numbers here let's say this is my pan number this is my LexA ID number okay so I'm initializing it right but actually what I'm doing over here is I'm actually hard coding the values so we don't need to hard code the values we don't need to initialize this particular objects okay we just need to let it go so we are going to tell somebody else and he is going to initialize he is going to insert he is going to inject all these values to its respective dependencies so what I mean by that is I told you that this name is a dependency home number is a dependency F is a dependence it says a dependencies and we are not going to initialize it just like this that I did in the slide I don't need to do this kind of thing I don't need to hard-code this no hard coding is required rather I'm going to tell all this values to somebody to one of your best friend his name is spring I need to tell him that and after that I don't need to hard-code the value and the spring is going to inject all these particular values to its respective dependencies right so no hard coding record and spring is going to inject all the dependencies to the respective I mean to the respective dependencies it's going to inject all these particular values right so let's make it more clear right now okay so the dependency injection simply means injecting the dependencies right we have our dependency we and we should have some values for our dependency those value we are going to inject to the dependency and we are going to do it by using spring and how spring is going to do it we are going to learn it today in this video okay but we put that let's make it more clear okay so this is how our class should be it should have a name variable home number variable a variable age a variable important number variable as for our requirement because these are the thing that I depends on right so the name should have some values like a village 1 2 3 4 5 should be my home number my I should create a new family object I should create a new sub object and I should create a new ArrayList object and I need to insert few values I mean few important numbers to my eye MP numbers list right I mean this this is my reference variable I need to insert the values to this particular reference all right but these things we are not going to do it the spring is going to do it for us and he is going to inject all these values that's what I was talking about from the last two slide right so this is what we call the dependency injection so this part we don't need to write right we are going to set it off somewhere else we are going to tell spring that ok spring I want to insert the value of the Lodge for the field called name I want to insert the value 1 2 3 4 5 - the it called home number I need to insert the new family object to the to the dependency called ëthe okay or to the properties called F I want to insert the new job object to the property is called say or the or the dependency called J you got my point so this thing spring is going to do you are not going to write this code you are not going to hard code is just like putting the equals sign over here inside the same class right so no hard coding required my body and all this initialization stuff are going to be taken care by spring framework and spring is going to inject the dependencies these are the dependencies and spring is going to inject this particular values that's what we are going to learn it and how spring is going to do it that is by using a setter injection or by using a constructor injection so these are the two concept that I'm going to cover here in this tutorial I'm not going to bore you more let's go to the Eclipse and let's start coding right now alright guys so before I go ahead and before I start coding here I want to you know you know stay over here for a couple of minutes and I want you to figure out whatever the things that we have discussed over here whatever the variables that we have over here and whatever the dependencies or whatever the properties that we have over here what kind of properties they are so for an example this name is of string type this home number is of in type and I told you one thing all these properties are are over here they all are called dependencies right and these two kind of dependencies what type of dependency they are so in Java we called this kind of dependency as literals right so this name is of string type this home number is up in type so these are kind of literal values so we call it dependencies in form of literals right and what about this this F is a family type and family is a class you remember and does this J is the job type and job is a class you remember right you remember the diagram I mean that you have seen couple of slides before you just remember that we had a class called family right we had a class job so these are are also dependency but this this these are cross type this F is class type right this a is a class type or dis change of job type so we call this type of dependencies dependencies in form of objectives so we call this F type of dependency is kind of objective type right because this is a this belongs to a class called family right and what about this so if you look at this kind of dependencies this important number is of ArrayList type obviously I release is a class but it is a collection class right so this kind of dependencies are called as dependencies in form of collections right so dependencies could be in form of literals in form of objectives or in form of collections but today in this tutorial we are only going to concentrate on the dependencies are which are in form of literals right we are talking about this kind of dependencies right now we are going to see that how we are going to inject the value of name how we are going to insert the value of home number by using the setter injection and constructor injection by using Spring Framework all right that's it now let's go to eclipse I'm not going to bore you any more let's go for Eclipse right now [Music] [Music]
Info
Channel: Selenium Express
Views: 104,897
Rating: 4.8224244 out of 5
Keywords: dependency injection in spring framework, what is dependency injection in spring, spring framework dependency injection, spring dependency injection example step by step, spring important concepts, spring step by step tutorial for beginners, spring complete tutorial, why we use spring framework, spring autowired, spring by selenium express, spring dependency injection tutorial for beginners, spring framework training, spring framework tutorial, spring bean, ioc, abhilash, spring di
Id: vLMaFRgZjM0
Channel Id: undefined
Length: 19min 46sec (1186 seconds)
Published: Sat Jul 28 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.