Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:01:00+00:00 2026-05-27T05:01:00+00:00

I want to write my own simple DI framework. I want that it perform

  • 0

I want to write my own simple DI framework.
I want that it perform only this simple case like Spring does:

public interface IWriter {
    public void writer(String s);
}

@Service
public class MySpringBeanWithDependency {
    private IWriter writer;

    @Autowired
    public void setWriter(IWriter writer) {
        this.writer = writer;
    }

    public void run() {
        String s = "This is my test";
        writer.writer(s);
    }
}

@Service
public class NiceWriter implements IWriter {
    public void writer(String s) {
        System.out.println("The string is " + s);
    }
}

public class Main extends TestCase {

    @Test
    public void test() {

        ApplicationContext context = new ClassPathXmlApplicationContext(
                "META-INF/beans.xml");
        MySpringBeanWithDependency test = (MySpringBeanWithDependency) context
                .getBean("mySpringBeanWithDependency");
        test.run();
    }
}

The same case, but mb without an XML-file.

Can somebody explain the concept of this type of frameworks and write some code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:01:01+00:00Added an answer on May 27, 2026 at 5:01 am

    Guice is open source. You can browse the code here:
    http://code.google.com/p/google-guice/source/browse/

    Spring is also open source. You can download it here:
    http://www.springsource.org/download

    Browsing through either of these should satisfy the “write some code” part of your question.

    EDIT: It seems you are looking for the “magic”. It boils down to reflection. Spring and/or Guice use Java Reflection to find the appropriate setters (or fields) on the class and set the values. That’s it. Everything else is glue to make the whole system work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to write a getter that can not be deleted? I want to own
I want to write a unit test for a Django manage.py command that does
There's a question that looks like this one here: Create my own classList object
I want to write a method that does not block. The method doesn't return
I want to write batch file for my own php framework. for example i
This tutorial shows how to write my own simple Operating System: Write Your Own
Hello I want write my own desktop sharing application in Java. The application should
I want to write a browser-chat and write an own server in c++, because
I have created blank Asp.Net-MVC 3 web application and want to write my own
I want to write a JAR file that makes use of the javax servlet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.