Step 6 – refactoring the Program class
By refactoring the commands into their dedicated classes, the code to create and handle these commands will be removed from the Program
class.
Hence, the Program
class will now only be used to compose our application. More specifically, the Program
class will do the following:
- Instantiate the root command and register its subcommands.
- Instantiate and configure the
CommandLineBuilder
class and start the program. - Configure logging.
- Configure dependency injection of the
BookmarkService
service.
Here is the refactored code for the Program
class (note that some parts of the code, including using
statements, are not listed here for brevity and clarity):
using Microsoft.Extensions.DependencyInjection; class Program { static async Task<int> Main(string[] args) { FreeSerilogLoggerOnShutdown(); ...