How to build a dependency injection framework by myself?

Discussion in 'Java' started by =?iso-8859-1?B?bW9vcJk=?=, Aug 24, 2006.

  1. 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.
     
    =?iso-8859-1?B?bW9vcJk=?=, Aug 24, 2006
    #1
    1. Advertisements

  2. 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.
     
    Andrew Thompson, Aug 24, 2006
    #2
    1. Advertisements

  3. =?iso-8859-1?B?bW9vcJk=?=

    Chris Uppal Guest

    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
     
    Chris Uppal, Aug 24, 2006
    #3
  4. why on earth bother?

    just download PicoContainer - it does this exact thing and more and is
    fully tested and proved to work.
     
    AndrewMcDonagh, Aug 24, 2006
    #4
  5. Download Spring http://www.springframework.org/download, look at the source
    code.
     
    PerfectDayToChaseTornados, Aug 24, 2006
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.