Summary

Class:ProjectX.PublicApi.Startup
Assembly:ProjectX.PublicApi
File(s):C:\private\projects\projectx\backend\src\ProjectX.PublicApi\Startup.cs
Covered lines:60
Uncovered lines:0
Coverable lines:60
Total lines:117
Line coverage:100%
Branch coverage:83.3%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
ConfigureServices(...)3410080
Configure(...)32100100

File(s)

C:\private\projects\projectx\backend\src\ProjectX.PublicApi\Startup.cs

#LineLine coverage
 1using System;
 2using Microsoft.AspNetCore.Builder;
 3using Microsoft.AspNetCore.Hosting;
 4using Microsoft.AspNetCore.Http;
 5using Microsoft.Extensions.Configuration;
 6using Microsoft.Extensions.DependencyInjection;
 7using Microsoft.Extensions.Logging;
 8using ProjectX.PublicApi.Configuration;
 9using ProjectX.PublicApi.Extensions;
 10using ProjectX.PublicApi.Filters;
 11using ProjectX.Services;
 12using ServiceBase;
 13
 14namespace ProjectX.PublicApi
 15{
 16    public class Startup : IStartup
 17    {
 18        private readonly Microsoft.Extensions.Logging.ILogger _logger;
 19        private readonly IHostingEnvironment _environment;
 20        private readonly IConfiguration _configuration;
 21
 2422        public Startup(
 2423            IConfiguration configuration,
 2424            IHostingEnvironment environment,
 2425            ILogger<Startup> logger)
 26        {
 2427            this._logger = logger;
 2428            this._environment = environment;
 2429            this._configuration = configuration;
 2430        }
 31
 32        public IServiceProvider ConfigureServices(IServiceCollection services)
 33        {
 2434            this._logger.LogInformation("Services Configure");
 35
 36            // Application Options
 2437             var appOptions = _configuration.GetSection("App")
 2438               .Get<ApplicationOptions>() ?? new ApplicationOptions();
 39
 2440            services.AddSingleton(_configuration);
 2441            services.AddSingleton(appOptions);
 42
 2443            services.AddDataLayer(this._environment, this._configuration);
 2444            services.AddTwilio(this._environment, this._configuration);
 45
 2446            services.AddScoped<AuthContextAttribute>();
 2447            services.AddScoped<AppContext>();
 2448            services.AddScoped<AuthService>();
 2449            services.AddSingleton<CryptoService>();
 2450            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
 2451            services.AddSingleton<IDateTimeAccessor, DateTimeAccessor>();
 2452            services.AddCors();
 2453            services.AddMvc(this._environment, this._logger);
 54
 2455             if (this._environment.IsDevelopment())
 56            {
 157                services.AddDeveloperDocumentation();
 58            }
 59
 2460            this._logger.LogInformation("Services Configured");
 61
 2462            return services.BuildServiceProvider();
 63        }
 64
 65        public void Configure(IApplicationBuilder app)
 66        {
 2467            this._logger.LogInformation("Application Configure");
 68
 2469            var env = app.ApplicationServices
 2470                .GetRequiredService<IHostingEnvironment>();
 71
 2472            var options = app.ApplicationServices
 2473                .GetRequiredService<ApplicationOptions>();
 74
 4875            app.UseCors(x => x
 4876                .AllowAnyOrigin()
 4877                .AllowAnyMethod()
 4878                .AllowAnyHeader());
 79
 2480             if (this._environment.IsDevelopment())
 81            {
 182                app.UseDeveloperDocumentation();
 183                this._logger.LogInformation("Added Swagger docs, /swagger");
 84            }
 85
 2486            app.UseMvc();
 87
 88            #region Application Services
 89
 2490            var appLifetime = app.ApplicationServices
 2491                .GetRequiredService<IApplicationLifetime>();
 92
 2493            appLifetime.ApplicationStarted.Register(() =>
 2494            {
 4895                app.RunOnApplicationStartedExtensions();
 2496
 4897                _logger.LogInformation("Application Started");
 4898            });
 99
 24100            appLifetime.ApplicationStopping.Register(() =>
 24101            {
 25102                _logger.LogInformation("Application Stopping");
 24103
 25104                app.RunOnApplicationStoppingExtensions();
 25105            });
 106
 24107            appLifetime.ApplicationStopped.Register(() =>
 24108            {
 25109                _logger.LogInformation("Application Stopped");
 25110            });
 111
 112            #endregion
 113
 24114            this._logger.LogInformation("Application Configured");
 24115        }
 116    }
 117}