internal ContainerBuilder Setup(RegistryCliOptions options)
        {
            this.services.AddLogging(cfg => cfg
                                     .AddSimpleConsole(opt => ConfigureConsoleLogging(opt))
                                     .AddFilter((category, level) => FilterLoggingMessages(category, level))
                                     );

            services.AddTransient <IRegistryService, RegistryService>();

            this.services.AddHttpClient <IRegistryApiClient, RegistryApiClient>(client => ConfigureRegistryApiClient(client, options));

            return(this);
        }
Ejemplo n.º 2
0
        private static async Task SetupAndRun(RegistryCliOptions options)
        {
            Debugger.Launch();

            ServiceProvider container = ContainerBuilder.Create().Setup(options).Build();

            IRegistryService  registryService = container.GetRequiredService <IRegistryService>();
            ILogger <Program> programLogger   = container.GetRequiredService <ILogger <Program> >();

            try
            {
                await registryService.RunCliAsync(options);
            }
            catch (Exception exception)
            {
                programLogger.LogError(exception, exception.Message);
                throw;
            }
        }
 private static void ConfigureRegistryApiClient(System.Net.Http.HttpClient client, RegistryCliOptions options)
 {
     client.BaseAddress = new System.Uri(options.Hostname);
 }