I've got a class implementing an interface, with some 15 methods. The methods all need a string SectorId
that is passed onward to another service, which make the class looks like this:
public class A: IA {
public string A1(string sectorId, ....) => _otherService.B1(sectorId, ....);
public string A2(string sectorId, ....) => _otherService.B2(sectorId, ....);
public string A3(string sectorId, ....) => _otherService.B2(sectorId, ....);
public string A4(string sectorId, ....) => _otherService.B2(sectorId, ....);
...
}
Is it possible to get rid of the repetitive string sectorId
while still achieving the same objective? This class handles webAPI calls and is dependency injected to the controller which calls it.
I thought of having the sectorId as a constructor initialized parameter, but that would mean either not using the class as a DI singleton and, instead, scoping it to the request or not using DI altogether and just initializing it on every request. Is there a better way to handle this?
Aucun commentaire:
Enregistrer un commentaire