Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to build a dependency injection framework by myself?

Reply
Thread Tools

How to build a dependency injection framework by myself?

 
 
=?iso-8859-1?B?bW9vcJk=?=
Guest
Posts: n/a
 
      08-24-2006
Hi,
I am using a factory class to build instances. the factory method looks
like:

<code>
class MyFactory{
Item getItem(String key){
...}
}
</code>

and the key and class are configured in a file
key=com.abcd.ClassA
b=com.abcd.B

<code>Item</code> is an interface implemented by some of the above
classes mentioned inside the cofiguration file.

I want the factory class to read the configuration file and then
instantiate the given class and as a return value. But I have no idea
how to instantiate the class. I tried Class.forName() and seesm it is
not a good solution to this problem.

 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      08-24-2006
moop™ wrote:

Sub: How to build a dependency injection framework by myself?

<quips>
A general answer to ..
"How to xxx a yyy by myself?"
...might start with..

1) Don't request help from other people.
...
</quips>

...oh, and I don't know what the experts on this
sort of stuff will say, but it seems unlikely that
it will be possible to do 'plug-ins' without at
least a little classloader trickery..

Andrew T.

 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      08-24-2006
moopT wrote:

> I want the factory class to read the configuration file and then
> instantiate the given class and as a return value. But I have no idea
> how to instantiate the class. I tried Class.forName() and seesm it is
> not a good solution to this problem.


Assuming you want to do this yourself in order to learn about the relevant
techniques, why not start by looking at something small, such as picocontainer,
and see what they do ? Then read up on the classes, methods, and techniques
they use.

By all means ask more questions as you learn, but this isn't really the sort of
forum for a full description of the architectural options and challenges.

Also, a related question comes up fairly often here. Try checking Google's
archives for posts about "pluggable" components.

-- chris


 
Reply With Quote
 
AndrewMcDonagh
Guest
Posts: n/a
 
      08-24-2006
moop™ wrote:
> Hi,
> I am using a factory class to build instances. the factory method looks
> like:
>
> <code>
> class MyFactory{
> Item getItem(String key){
> ..}
> }
> </code>
>
> and the key and class are configured in a file
> key=com.abcd.ClassA
> b=com.abcd.B
>
> <code>Item</code> is an interface implemented by some of the above
> classes mentioned inside the cofiguration file.
>
> I want the factory class to read the configuration file and then
> instantiate the given class and as a return value. But I have no idea
> how to instantiate the class. I tried Class.forName() and seesm it is
> not a good solution to this problem.
>


why on earth bother?

just download PicoContainer - it does this exact thing and more and is
fully tested and proved to work.

 
Reply With Quote
 
PerfectDayToChaseTornados
Guest
Posts: n/a
 
      08-24-2006
"moopT" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi,
> I am using a factory class to build instances. the factory method looks
> like:
>
> <code>
> class MyFactory{
> Item getItem(String key){
> ..}
> }
> </code>
>
> and the key and class are configured in a file
> key=com.abcd.ClassA
> b=com.abcd.B
>
> <code>Item</code> is an interface implemented by some of the above
> classes mentioned inside the cofiguration file.
>
> I want the factory class to read the configuration file and then
> instantiate the given class and as a return value. But I have no idea
> how to instantiate the class. I tried Class.forName() and seesm it is
> not a good solution to this problem.
>


Download Spring http://www.springframework.org/download, look at the source
code.

--
pdtct


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Is it in the C++ culture to use Dependency Injection/Inversion ofControl? Danno C++ 12 04-10-2008 08:08 PM
What is Dependency Injection? Anonieko ASP .Net 2 10-14-2007 12:03 PM
Dependency Injection in C++ Michael Feathers C++ 5 10-13-2006 08:23 AM
SWsoft Acronis Disk Director Suite 9.0 Build 508, Acronis OS Selector 8.0 Build 917, Acronis Partition Expert 2003 Build 292, Acronis Power Utilities 2004 Build 502, F-SECURE.ANTI vIRUS.PROXY v1.10.17.WINALL, F-SECURE.ANTI vIRUS v5.50.10260 for CITRI vvcd Computer Support 0 09-25-2004 01:38 AM



Advertisments