1+ using Exam . Application ;
2+ using Exam . Application . Common . Interfaces ;
3+ using Exam . Infrastructure ;
4+ using Exam . Persistence ;
5+ using Exam . Persistence . Context ;
6+ using FluentValidation . AspNetCore ;
7+ using Microsoft . AspNetCore . Builder ;
8+ using Microsoft . AspNetCore . Hosting ;
9+ using Microsoft . AspNetCore . Mvc ;
10+ using Microsoft . Extensions . Configuration ;
11+ using Microsoft . Extensions . DependencyInjection ;
12+ using Microsoft . Extensions . Hosting ;
13+
14+ namespace Exam . Clients . WebApi
15+ {
16+ public class Startup
17+ {
18+ public Startup ( IConfiguration configuration , IWebHostEnvironment environment )
19+ {
20+ Configuration = configuration ;
21+ Environment = environment ;
22+ }
23+
24+ public IConfiguration Configuration { get ; }
25+ public IWebHostEnvironment Environment { get ; }
26+
27+ // This method gets called by the runtime. Use this method to add services to the container.
28+ public void ConfigureServices ( IServiceCollection services )
29+ {
30+ services . AddInfrastructure ( ) ;
31+ services . AddPersistence ( Configuration ) ;
32+ services . AddApplication ( ) ;
33+
34+ services . AddHealthChecks ( ) . AddDbContextCheck < FilmsDbContext > ( ) ;
35+
36+ services . AddHttpContextAccessor ( ) ;
37+
38+ services . AddControllers ( )
39+ . AddFluentValidation ( fv => fv . RegisterValidatorsFromAssemblyContaining < IFilmsDbContext > ( ) ) ;
40+
41+ services . Configure < ApiBehaviorOptions > ( options => options . SuppressModelStateInvalidFilter = true ) ;
42+ }
43+
44+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
45+ public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
46+ {
47+ if ( env . IsDevelopment ( ) )
48+ {
49+ app . UseDeveloperExceptionPage ( ) ;
50+ app . UseDatabaseErrorPage ( ) ;
51+ }
52+ else
53+ {
54+ app . UseHsts ( ) ;
55+ }
56+
57+ app . UseHealthChecks ( "/health" ) ;
58+ app . UseHttpsRedirection ( ) ;
59+
60+ app . UseRouting ( ) ;
61+
62+ app . UseAuthorization ( ) ;
63+
64+ app . UseEndpoints ( endpoints => endpoints . MapControllers ( ) ) ;
65+ }
66+ }
67+ }
0 commit comments