I use Guice in my java application for dependency injection. And I would like to restrict some object types for injecting into any class. That's because I have some sort of plugin api and it would't be OK if any object could be injected into a plugin. So, I need to restrict some core classes from injecting into plugin classes. Is there a way to do this or I probably should inject these core classes manually, without using Guice?
0
votes
1 Answers
0
votes
Your title and question don't match.
The answer to the title is yes, obviously - what else can you inject into, and what can Guice create instances of, if not concrete classes?
The answer to your question is that you can prevent A from being injected into B by preventing compilation of B if it uses A - either by restricting visibility (as in public, private), or by structuring your build so that the A is not on the class path when compiling B.