コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Following lines can throw if configuration is not correctly set.
            // This correctly prevents container from starting in error scenario.
            // Might throw->
            var healthCheckModel = new HealthCheckModel()
            {
                LivenessCheck  = Configuration.GetValue <bool>("livenessCheck"),
                ReadinessCheck = Configuration.GetValue <bool>("readinessCheck")
            };

            IHealthCheckRepository healthCheckRepository = new HealthCheckRepository();
            IWebhookHandler        webhookHandler        = new WebhookHandler(Configuration["webhook"]);

            webhookHandler.InvokeAsync(WebhookEvents.AppStarted, healthCheckRepository.Get()).Wait();
            // <-Might throw

            services.AddSingleton(webhookHandler);
            services.AddSingleton(healthCheckRepository);

            services.AddSingleton <Microsoft.Extensions.Hosting.IHostedService, BackgroundReportingService>();
            services.AddMvc();
        }