I have a Windows Forms application that currently loads a database on startup. The flow is like this:
Program.cs => Application.Run(new MainForm()); => MainForm Constructor => Open Database
So basically MainForm holds all the bits and pieces that make the application run, while Program.cs is just a stub. Currently, the name of the database that is loaded is hardcoded, and I want to add functionality to specify the name of the database to load through the command line. At the same time, I want to add the ability to do some Unit Testing or even Dependency Injection later on, so I wonder which approach is recommended?
- Change the constructor of MainForm to accept some parameters. Then change Program.cs to read the command line and change the call to
Application.Run(new MainForm());
accordingly - Leave Program.cs and the Signature of the constructor untouched and check the command line in the constructor of MainForm
Method one seems to be cleaner as it would allow i.e. a Test runner to create MainForm with a test database, but as I'm usually not a WinForms developer I do not know if there could be side effects of not having a default constructor on the Main Form or if there is a better approach?