Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   How to build a dependency injection framework by myself? (http://www.velocityreviews.com/forums/t366309-how-to-build-a-dependency-injection-framework-by-myself.html)

=?iso-8859-1?B?bW9vcJk=?= 08-24-2006 04:15 AM

How to build a dependency injection framework by myself?
 
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.


Andrew Thompson 08-24-2006 04:44 AM

Re: How to build a dependency injection framework by myself?
 
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.


Chris Uppal 08-24-2006 09:46 AM

Re: How to build a dependency injection framework by myself?
 
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



AndrewMcDonagh 08-24-2006 05:56 PM

Re: How to build a dependency injection framework by myself?
 
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.


PerfectDayToChaseTornados 08-24-2006 06:57 PM

Re: How to build a dependency injection framework by myself?
 
"moopT" <samhng@gmail.com> wrote in message
news:1156392915.847058.81820@p79g2000cwp.googlegro 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




All times are GMT. The time now is 11:20 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.