Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Refactor the command line code, so that it can be reused in multiple services. #640

Description

Description

When we fork a repo and build a service on top of it, currently it is hard to sync back any updates done to this repo. And if we have build multiple services then we need to go and make changes to all corresponding services.

Expected Behavior

All the common code can be extracted to a separate library so that our Program.cs remains neat and clean. When we build multiple micro services in client environment we can just reference the common library and it will be easy to sync any changes from the main github repo as we will need to make changes at just one place.

We can extract all the common logic written in Program.cs and CommandLine.cs to a separate class library e.g Helium.Core and reference that in our web api project.

Here is how the Program.cs will look like after refactoring:

public class Program
    {
        public static async Task<int> Main(string[] args)
        {

            var host = CreateHostBuilder();

            // build the System.CommandLine.RootCommand
            RootCommand root = CommandLineHelper.BuildRootCommand();
            root.Handler = CommandHandler.Create<string, AuthenticationType, LogLevel, bool>(CommandLineHelper.RunApp);

            // run the app
            return await root.InvokeAsync(CommandLineHelper.CombineEnvVarsWithCommandLine(args,host)).ConfigureAwait(false);
        }

        public static IWebHostBuilder CreateHostBuilder() =>
            WebHost.CreateDefaultBuilder().UseStartup<Startup>();                
    }

Metadata

Metadata

Labels

BugSomething isn't workingC#

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions