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 7580351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:53:47+00:00 2026-05-30T17:53:47+00:00

I would like to build my own custom DI framework based on Java annotations

  • 0

I would like to build my own custom DI framework based on Java annotations and I need a little direction to get started. I know it would be much easier to use one of the many wonderful frameworks out there such as guice or spring, but for the sake of my own curiosity, i’d like to build my own.

I’m not very familiar with annotations, so i’m having a bit of trouble finding resources and would really appreciate someone just sort of spelling out a few of the steps i’ll need to take to get started.

As fore mentioned, id like to take a factory approach and somehow label my getters with an @Resource or @Injectable type annotation, and then in my business classes be able to set my variable dependencies with an @Inject annotation and have the resource automatically available.

Does anyone have any sort of resource they can pass along to help me understand the process of tagging methods based on annotations and then retrieving values from a separate class based on an annotation. A little direction is all I need, something to get me started. And of course i’ll be happy to post a little code sample here once I get going, for the sake of others future reading of course.

EDIT

The resources I am using to put this together:

Java Reflection: Annotations

How to find annotations in a given package: Stack Overflow ?

Scanning Annotations at Runtime

I have not actually finished writing this yet, but the basic task list is going to be as follows (for anyone who might be interested in doing something similar in the future)

  1. At class runtime scan for all @Inject fields and get object type.

  2. Scan all classes (or just a specific package of classes (I haven’t
    decided yet)) for annotated methods @InjectableResource.

  3. Loop all annotated methods and find the method that returns the
    object type I am looking for.

  4. Run the method and get the dependency.

It will also be helpful to note that when scanning all the classes I will be using a library called Javassist. Basically what this does is allows me to read the bytecode information of each class without actually loading the class. So I can read the annotation strings without creating serious memory problems.

  • 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-30T17:53:48+00:00Added an answer on May 30, 2026 at 5:53 pm

    Interesting that you want to build your own. I love Google Guice – it makes code so elegant and simple.

    I’ve used this guide before which I found pretty useful for learning about annotations and how you can pull them out of classes and methods.

    You will have to define your own Annotations which is done using @interface. Then you will have to define some kind of class for doing bindings e.g. where you see an interface bind in this concrete class. Finally, you will need some logic to pull it altogether e.g. go through each class, find each annotation, and then find a suitable binding.

    Give consideration to things like lazy instantiation through Reflections and singletons. Guice, for example, allows you to use a singleton so your only using one instance of the concrete class, or you can bind a new version each time.

    Good luck!

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

Sidebar

Related Questions

I build a composite widget and would like it to have it's own accelerators
I would like to build a regexp in Java that would be passed in
I want to build my own custom view which should look like the Crysis-GUI.
I would like to build an application that will run on a web, this
I would like to build a query that will pull the number of rows
I would like to build an excel VBA program to find all the match
I would like to build some code which calls some code on loadup of
I would like to build a static version of QT Library for X11 like
I would like to build a cross-platform GUI application in Python that displays PostScript
I would like to build some smaller scale but hightly customized documentation sites for

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.