SonarLint and others checking tools will warn you if you're injecting services through variable members in Java Spring-Boot:
@Autowired
private DepartementDataset datasetDepartements;
public CogDataset() {
}
you should better inject them through the constructor, they are telling.
private DepartementDataset datasetDepartements;
@Autowired
public CogDataset(DepartementDataset datasetDepartements) {
this.datasetDepartements = datasetDepartements;
}
I guess it's related to hexagonal architecture, to make the creation of custom components for testing more easy. But I'm not sure of this.
But if you're using a recent version of Angular, you will quickly be warned of the opposite. Are you injecting through a constructor?
export class PresentationComponent {
constructor(private readonly communeService: CommuneService) {
}
Your IDE has chances to recommend you to switch to:
export class PresentationComponent {
private readonly communeService: CommuneService = inject(CommuneService);
constructor() {
}
Of course, every programming language makes the choices it wants, but what are the underlying motives of promoting one form or the other?
At the time of language design, how do you pose yourself the problem? What do you consider to make the choice that you will recommend?