1

In the command line exe application in the windows service app that I have, there is a main method and that's where I'm registering all the dependencies using a simple injector IoC. That's my composition root now. In the same windows service application, there is a OnStart overridable method. That's where I'm doing an ETL operation.

Where should I keep the composition root? In the main method or OnStart?

wonderful world
  • 8,704
  • 14
  • 76
  • 142

1 Answers1

2

Where should I keep the composition root? In the main method or OnStart?

Both are valid locations for your Composition Root. Both Main and your OnStart can be used as Composition Root. I've used both locations in the past myself. Typically, I create a separate Bootstrapper or CompositionRoot class that contains the application's Composition Root, and call that Composition Root either directly from the main, or from within my ServiceBase derivative.

Steven
  • 151,500
  • 20
  • 287
  • 393