Where to inject class. In using class or in caller class
<p>I have a PropertiesUtil class which is used as container for some configuration properties of my <code>application.properties</code> file.</p>

<pre><code>@Component
@ConfigurationProperties(prefix = "application.property")
public abstract class PropertiesUtil {

    private String networkLocation;
    private String topLevelPrefix;
</code></pre>

<p>I have to use this class on different places in my application.</p>

<p><strong>My question is</strong> should I inject this class on every place I need it or should I inject this class on a caller class and give it as parameter to a method. </p>

<p>For example injection in using class:</p>

<pre><code>@Component
public class FileExport {

    private final PropertiesUtil propertiesUtil;

    @Autowired
    public FileExport(PropertiesUtil propertiesUtil) {
        this.propertiesUtil = propertiesUtil;
    }

    public List&lt;File&gt; getListOfFileAndRules(String topLevelName){
      // logic and use of propertiesUtil
    }
</code></pre>

<p>or for example injection in caller class:</p>

<pre><code>@Component
public class AnyClass{

    private final PropertiesUtil propertiesUtil;
    private final FileExport fileExport;

    @Autowired
    public AnyClass(PropertiesUtil propertiesUtil, FileExport fileExport) {
        this.propertiesUtil = propertiesUtil;
        this.fileExport= fileExport;
    }

    public void anyMethod(){
        List&lt;file&gt; fiels = fileExport.getListOfFileAndRules(anyString, propertiesUtil);
     }
</code></pre>