Skip to main content
2 of 3
added 2 characters in body
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

A composition root doesn't have to stand completely alone. Sure, it gives you a lot of flexibility if it's flat and procedural but the longer that gets the more it numbs the brain. Always keep in mind what it's going to be like maintaining this code.

It is perfectly ok to break up this code and make something else deal with some of this complexity. Keep what's managed here simple and accessible. That way looking at it, and changing it, is relaxing. Not overwhelming.

A humble example:

private static Form1 Form1Factory(string SqlConnString) { return new Form1( new FooCellsFactoryBuilder( new SqlContext(SqlConnString) ).build(), new BarCellsFactoryBuilder( new SqlContext(SqlConnString) ).build(), new OtherCellsFactoryBuilder( new SqlContext(SqlConnString) ).build(), new MyColumnFactoryBuilder( new SqlContext(SqlConnString) ).build(), new EdgeCaseFactoryBuilder( new SqlContext(SqlConnString) ).build(), ) ; } 
candied_orange
  • 119.7k
  • 27
  • 233
  • 369