Is it a good practice to pass an argument that is an injectable service to a function?
Hello everyone, I have been doing some research but have not found a definitive answer to the question above yet. I am currently working with Angular and came across some code that has left me confused about what practice to follow or avoid.
Scenario:
shopping-util.ts
export class ShoppingUtil {
public static buildShopingNote(material, bService: BService) {
if (!material) {
return '';
}
return bService.doSomeThing(material);
}
}
b-service.ts
@Injectable()
export class BService {
public doSomeThing(input): string {
let result = 'do something with input';
return result;
}
}
I am wondering if we should move the function 'buildShopingNote' to a business service instead so that we can inject the BService when the service is initialized? And would the same answer apply for other programming languages (Java, C ..) as well, in your opinion?
Any ideas are appreciated!