I would like to create my own custom DI framework based on Java annotations, and I need a little guidance to get started. I know that it would be much easier to use one of many great frameworks like guice or spring, but for the sake of my own curiosity I would like to build my own.
I am not very familiar with annotations, so I have problems finding resources, and I really would like someone to just describe a few steps that I need to take to get started.
As mentioned above, id would like to take a factory approach and somehow label my getters using the @Resource or @Injectable annotation, and then in my business classes you can set my variable dependencies using the @Inject annotation and have the resource automatically.
Does anyone have any resource that they can pass to help me understand the process of annotation-based labeling, and then get the values ββfrom a separate class based on the annotation. A little direction is all I need to get me started. And, of course, I will be happy to post a small sample code here as soon as I go, for the sake of other future readings, of course.
EDIT
Resources I use to combine:
Java Reflection: Annotations
How to find annotations in this package: stack overflow?
Scan annotations at runtime
I have not finished writing this yet, but the main list of tasks will be as follows: (for those who may be interested in doing something similar in the future)
In the mode of checking the execution of the class for all @Inject fields and obtaining the type of the object.
Scan all classes (or just a specific class package (I havenβt decided yet)) for annotated @InjectableResource methods.
Complete all annotated methods and find a method that returns the type of object I'm looking for.
Run the method and get the dependency.
It will also be useful to note that when scanning all classes I will use the Javassist library. Basically, this allows me to read bytecode information of each class without actually loading the class. Therefore, I can read lines of annotations without creating serious memory problems.