Skip to content
This repository has been 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

Open
sapinderpalsingh opened this issue Mar 1, 2021 · 0 comments
Assignees
Labels
Bug Something isn't working C#

Comments

@sapinderpalsingh
Copy link

sapinderpalsingh commented Mar 1, 2021

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>();                
    }
@sapinderpalsingh sapinderpalsingh added Bug Something isn't working C# labels Mar 1, 2021
@sapinderpalsingh sapinderpalsingh self-assigned this Mar 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Something isn't working C#
Projects
None yet
Development

No branches or pull requests

1 participant