GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Spring
Go To First  |  Previous Question  |  
 Spring  |  Question 2 of 2    Print  
dependency injection
what is dependency injection ??


  
Total Answers and Comments: 7 Last Update: October 19, 2009     Asked by: retheesh 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: aparna210
 

 Objects can be injected through setter or constructor.
Dependency Injection means we can inject all the dependenciess to ur object in the xml file.

For example in order to establish connection ,Connection object needs datasource object.

So in the xml file first we declare a bean for DataSource ,in that we give parameters for connecting to database like url username passwordetc
We delare another bean named Connection in which the above declared datasource object is injected through setter or constructor.

So at the time of startup the container reads the xml file. ann all the required objects are created without the developer explicitly creating objects.
 



Above answer was rated as good by the following members:
geeky920
January 11, 2008 09:48:05   #1  
Rajeev_y69 Member Since: December 2006   Contribution: 1    

RE: dependency injection
Dependency injection or Inversion of control are the two terms used for same thing. In case of DI we define the process of instatiating an object into a non java class generally xml file.

Instead of using new word to instatiate any object reference of an object is retrieved from an config file.

 
Is this answer useful? Yes | No
May 11, 2008 13:53:01   #2  
Karuna Reddy Member Since: June 2007   Contribution: 40    

RE: dependency injection
Depedency Injection is nothing but IoC. dynamically issue the object when asked by the client.
 
Is this answer useful? Yes | No
May 11, 2008 13:55:39   #3  
Karuna Reddy Member Since: June 2007   Contribution: 40    

RE:
The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file.
 
Is this answer useful? Yes | No
June 26, 2008 02:38:04   #4  
aparna210 Member Since: June 2008   Contribution: 2    

RE: dependency injection

Objects can be injected through setter or constructor.
Dependency Injection means we can inject all the dependenciess to ur object in the xml file.

For example in order to establish connection Connection object needs datasource object.

So in the xml file first we declare a bean for DataSource in that we give parameters for connecting to database like url username passwordetc
We delare another bean named Connection in which the above declared datasource object is injected through setter or constructor.

So at the time of startup the container reads the xml file. ann all the required objects are created without the developer explicitly creating objects.


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 29, 2008 00:42:49   #5  
Karuna Reddy Member Since: June 2007   Contribution: 40    

RE: dependency injection
Dependency Injection is also know as IoC(Injection of control)

By using this Injectioin we can instantiates and creates the objects for the non-java class using XMl file

its bean based defination And give the instance whenever asked by the client called Dependeny Injection


Please update it if any thing else

 
Is this answer useful? Yes | No
July 01, 2008 03:20:27   #6  
rajeevchaturvedi2007 Member Since: February 2008   Contribution: 2    

RE: dependency injection
Dependency injection is the ability to inject collobrative objects dynamically.Suppose you want to call a method of particular class so for that you use new operator help and make object of that class and call the require method using ref. varibale of that class .But when you use Spring dependency injection you don't have to do all these stuff instead of that you configure a xml file in which you mention what all objects you require in you class it will get ready for use. You don't have to create or instantiate .

cheers

Rajeev Chaturvedi

 
Is this answer useful? Yes | No
October 19, 2009 00:28:10   #7  
karayi Member Since: March 2009   Contribution: 1    

RE: dependency injection
Dependency Injection means instead of an object looking up dependencies from the container the container gives the dependent object at instantiation time without waiting to be asked.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape