I have this class
class Foo {
private readonly serviceA : AService;
private readonly serviceB : BService;
private readonly serviceC : CService;
...
constructor() {
this.setupService();
...
}
private setupService() : void {
this.serviceA = new ServiceA(...);
this.serviceB = new ServiceB(...);
...
}
}
as you can see I would like to set the fields using setupServices method which will be called from the contractor only. of course, this will fail to compile but I'm wondering if there is a way to get around this.
the reason I want this to clean up the contractor.
I could do this
constructor() {
this.serviceA = new AService(...);
this.serviceB = new BService(...);
...
}
but this will make a mass when I have many services