File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Dependency Injection, can it solve my problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Dependency Injection, can it solve my problem" Watch "Dependency Injection, can it solve my problem" New topic
Author

Dependency Injection, can it solve my problem

Vladislav Simovic
Ranch Hand

Joined: Feb 03, 2011
Posts: 37
I have posted a little while ago topic with my problem and it was suggested that DI can solve it. I have been reading about DI since then and from first look it doesnt seem like it can. Here is my problem:

My project is to build a module for testing databases. That module needs to be integrated into larger interface. My module doesnt have any resources of his own, every resource he needs he gets form server.

What my module does? When server makes new instance of my module it passes him some resources. Then module returns a proper JSF page that will be included into main interface page. Backend JSF mechanism creates a bean for that page. That bean is created automatically. So how can that bean take the needed resources from module?
One way is to put those resources into session, and than bean takes them from there. Problem is there can be multiple database testing and at same time multiple instances of module can exist in users session. How does the bean know which data to take from session? He doesnt.

So my question is this, how can you inject already made instance of a module(this object exists before creating of a bean) into field of a bean?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

Dependency Injection is nothing more than a process where beans are wired together from outside rather than requiring the beans to reach out and find stuff (which requires them to have explicit logic coded into them).

For actual database testing, you might want to look at dbUnit. You can create a JSF webapp, and you can definitely inject objects to be tested into it, but that may be overkill for you.


Customer surveys are for companies who didn't pay proper attention to begin with.
Vladislav Simovic
Ranch Hand

Joined: Feb 03, 2011
Posts: 37
Tim Holloway wrote:Dependency Injection is nothing more than a process where beans are wired together from outside rather than requiring the beans to reach out and find stuff (which requires them to have explicit logic coded into them).

For actual database testing, you might want to look at dbUnit. You can create a JSF webapp, and you can definitely inject objects to be tested into it, but that may be overkill for you.


Tnx for the info, I really dont time now to look into whole matter of dependency injection, only to find out that it doesnt solve my problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dependency Injection, can it solve my problem
 
Similar Threads
long post IBM.158
Representation of SessionBeans in UML Sequence Diagrams
EJBCore_Spec errata?
How to modify JSF page during runtime?
Make SERVLET talk to EJB