DEV Community

Discussion on: Understanding Dependency Injection by writing a DI Container - from scratch! (Part 3)

martinhaeusler profile image
Martin Häusler Author

Hi! Sorry for the late response, somehow your "@" mention didn't work and I didn't get notified about your answer.

The XML/Text files you refer to would replace the classpath scan. Instead of scanning all classes, you'll read a predefined list of service class names from a file, typically XML. Let's simplify it a bit and use plain text, for example:

(left is interface, right is implementation)

org.example.api.MyServiceA, org.example.impl.MyServiceAImpl
org.example.api.MyServiceB, org.example.impl.MyServiceBImpl
Enter fullscreen mode Exit fullscreen mode

This would tell you that the interface "MyServiceA" is implemented by a class "MyServiceAImpl". To find the classes, you'd simply have to use Class.forName(className). Use those interface/class pairs instead of the classpath scan.

tee12345 profile image
Babatunde Raimi Lawal

Thanks a lot, I'm very grateful.