-
Notifications
You must be signed in to change notification settings - Fork 998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implemented Injector class #1022
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this pull request! 😊 While the overall implementation is solid and aligns well with the task requirements, there are a few critical issues that need to be addressed before we can proceed. Specifically, the createNewInstance
method is being called twice unnecessarily, which could lead to performance inefficiencies. Additionally, the findImplementation
method may return null, which could cause runtime errors if not handled properly. Lastly, the clazzImplementationInstance
variable should be initialized more safely to prevent potential null pointer exceptions. Please address these issues to ensure the robustness and efficiency of your code. Keep up the great work, and I look forward to your revisions! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
|
||
public static Injector getInjector() { | ||
return injector; | ||
} | ||
|
||
public Object getInstance(Class<?> interfaceClazz) { | ||
return null; | ||
Object clazzImplementationInstance = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable clazzImplementationInstance is initialized to null but is not immediately assigned a value. Consider initializing it with createNewInstance(clazz) after checking for the @Inject annotation to avoid potential null pointer exceptions.
|
||
public static Injector getInjector() { | ||
return injector; | ||
} | ||
|
||
public Object getInstance(Class<?> interfaceClazz) { | ||
return null; | ||
Object clazzImplementationInstance = null; | ||
Class<?> clazz = findImplementation(interfaceClazz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The findImplementation method may return null if the interfaceClazz is not found in the interfaceImplementations map. Consider adding a check to handle this scenario and throw an appropriate exception if no implementation is found.
Object fieldInstance = getInstance(field.getType()); | ||
clazzImplementationInstance = createNewInstance(clazz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The createNewInstance method is called twice for the same clazz, once inside the loop and once after the loop. This could lead to unnecessary object creation. Consider restructuring the code to call createNewInstance only once after all fields are processed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on implementing the code! 🎉 While the overall implementation is solid, please ensure that all classes intended for injection are annotated with @component to avoid runtime exceptions. Additionally, double-check the Injector class configuration to ensure it returns the correct instances. Keep up the good work and continue learning from these experiences!
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
ProductService productService = (ProductService) injector.getInstance( | ||
ProductService.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the Injector class is correctly implemented and configured to return an instance of ProductService. If the Injector is not properly set up, this line may cause a runtime error.
if (!clazz.isAnnotationPresent(Component.class)) { | ||
throw new RequiredAnnotationAbsenceException( | ||
"Cannot create an instance of the class without Component annotation " | ||
+ clazz); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that all classes you intend to create instances for are annotated with @component. Otherwise, the RequiredAnnotationAbsenceException will be thrown, as seen in this check.
No description provided.