Dependency Injection, can it solve my problem

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?

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

posted May 10, 2011 11:31:28

0

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.