Esempio n. 1
0
        protected void ConfigureClients(IServiceCollection services)
        {
            ServiceProvider serviceProvider = services.BuildServiceProvider();

            IImmunizationService service = serviceProvider.GetService <IImmunizationService>();

            if (service is MinistryOfHealthImmunizationService)
            {
                if (string.IsNullOrEmpty(ImmunizationEnvironment.MedicalLogApi.Url))
                {
                    if (string.IsNullOrEmpty(Configuration["MedicalLogApiUrl"]))
                    {
                        throw new ConfigurationErrorsException("Url of the medical log API not defined. Set the environment variable 'MEDICAL_LOG_API_URL' or a user secret with 'dotnet user-secrets set \"MedicalLogApiUrl\" \"{url}\"'");
                    }
                    ImmunizationEnvironment.MedicalLogApi.Url = Configuration["MedicalLogApiUrl"];
                }
                if (string.IsNullOrEmpty(ImmunizationEnvironment.MedicalLogApi.Bearer))
                {
                    if (string.IsNullOrEmpty(Configuration["MedicalLogBearer"]))
                    {
                        throw new ConfigurationErrorsException("JWT of the medical log API not defined. Set the environment variable 'MEDICAL_LOG_BEARER' or a user secret with 'dotnet user-secrets set \"MedicalLogBearer\" \"{jwt}\"'");
                    }
                    ImmunizationEnvironment.MedicalLogApi.Bearer = Configuration["MedicalLogBearer"];
                }

                // Clients
                services.AddHttpClient <IMedicalLogClient, MedicalLogClient>(client =>
                {
                    client.BaseAddress = new Uri(ImmunizationEnvironment.MedicalLogApi.Url);
                    client.DefaultRequestHeaders.Add("Authorization", "Bearer " + ImmunizationEnvironment.MedicalLogApi.Bearer);
                });
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmunizationController"/> class.
 /// </summary>
 /// <param name="logger">Injected Logger Provider.</param>
 /// <param name="svc">The immunization data service.</param>
 /// <param name="httpContextAccessor">The Http Context accessor.</param>
 public ImmunizationController(
     ILogger <ImmunizationController> logger,
     IImmunizationService svc,
     IHttpContextAccessor httpContextAccessor)
 {
     this.logger              = logger;
     this.service             = svc;
     this.httpContextAccessor = httpContextAccessor;
 }