Skip to main content
added 20 characters in body
Source Link
Ewan
  • 84.5k
  • 5
  • 91
  • 189

Huge DI setup classes are a problem. But think of the code it replaces.

You need to instantiate all those services and whatnot. The code to do so would either be in the app.main() starting point and manually injected, or tightly coupled as this.myService = new MyService(); within the classes.

Reduce the size of your setup class by splitting it out into multiple setup classes and call them from the program start point. ie.

main() { var c = new CiContainerdiContainer(); var service1 = cidiSetupClass.SetupService1(c); var service2 = cidiSetupClass.SetupService2(c, service1); //if service1 is required by service2 //etc //main logic } 

You don't need to reference service1 or 2 except to pass them into other ci setup methods.

This is better than attempting to get them from the container as it enforces the order of calling the setups.

Huge DI setup classes are a problem. But think of the code it replaces.

You need to instantiate all those services and whatnot. The code to do so would either be in the app.main() starting point and manually injected, or tightly coupled as this.myService = new MyService(); within the classes.

Reduce the size of your setup class by splitting it out into multiple setup classes and call them from the program start point. ie.

main() { var c = new CiContainer(); var service1 = ci.SetupService1(c); var service2 = ci.SetupService2(c, service1); //if service1 is required by service2 //etc //main logic } 

You don't need to reference service1 or 2 except to pass them into other ci setup methods.

This is better than attempting to get them from the container as it enforces the order of calling the setups.

Huge DI setup classes are a problem. But think of the code it replaces.

You need to instantiate all those services and whatnot. The code to do so would either be in the app.main() starting point and manually injected, or tightly coupled as this.myService = new MyService(); within the classes.

Reduce the size of your setup class by splitting it out into multiple setup classes and call them from the program start point. ie.

main() { var c = new diContainer(); var service1 = diSetupClass.SetupService1(c); var service2 = diSetupClass.SetupService2(c, service1); //if service1 is required by service2 //etc //main logic } 

You don't need to reference service1 or 2 except to pass them into other ci setup methods.

This is better than attempting to get them from the container as it enforces the order of calling the setups.

Source Link
Ewan
  • 84.5k
  • 5
  • 91
  • 189

Huge DI setup classes are a problem. But think of the code it replaces.

You need to instantiate all those services and whatnot. The code to do so would either be in the app.main() starting point and manually injected, or tightly coupled as this.myService = new MyService(); within the classes.

Reduce the size of your setup class by splitting it out into multiple setup classes and call them from the program start point. ie.

main() { var c = new CiContainer(); var service1 = ci.SetupService1(c); var service2 = ci.SetupService2(c, service1); //if service1 is required by service2 //etc //main logic } 

You don't need to reference service1 or 2 except to pass them into other ci setup methods.

This is better than attempting to get them from the container as it enforces the order of calling the setups.