-
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
feat: implemented dependency injection mechanism #1024
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.
Great job on implementing the dependency injection framework! 🎉 Your code meets the core requirements and is mostly well-structured. There are a few minor improvements you could consider, such as adding @Target
to your custom annotations and using ReflectiveOperationException
for more specific exception handling. Also, ensure that all classes meant for injection are annotated with @Component
to avoid runtime issues. Keep up the great work and happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
return instances.get(interfaceClazz); | ||
} | ||
Class<?> clazz = findImplementation(interfaceClazz); | ||
if (clazz == null || !clazz.isAnnotationPresent(Component.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 Component
annotation is correctly applied to all classes that should be managed by the injector. If a class is missing this annotation, it will cause a RuntimeException
.
} | ||
Class<?> clazz = findImplementation(interfaceClazz); | ||
if (clazz == null || !clazz.isAnnotationPresent(Component.class)) { | ||
throw new RuntimeException("No implementation found for: " + interfaceClazz.getName()); |
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.
Consider providing more detailed error messages or logging to help diagnose issues when no implementation is found.
for (Field field : clazz.getDeclaredFields()) { | ||
if (field.isAnnotationPresent(Inject.class)) { | ||
field.setAccessible(true); | ||
Object fieldInstance = getInstance(field.getType()); |
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 circular dependencies are not present, as this could lead to a StackOverflowError
during instance creation.
feat: implemented dependency injection mechanism using @component and @Inject annotations