How to prevent class instantiation with dependency injection? : <p>I had an interview question that asked roughly the following: with dependency injection, how do you prevent all of the classes from being instantiated? What if you only want a few, but not all? There are good reasons, they said, for example to avoid them all being in memory at the same time...</p>

<p>I've tried to research this question but it's hard to even figure out the best search term is. And no answers could I find. </p>
