1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Threading . Tasks ;
5- using Facware . Data . Access ;
1+ using Facware . Api . Extensions ;
62using Facware . Data . Access . Base . Base ;
73using Facware . Data . Access . Repository . Implementation ;
84using Facware . Data . Access . Repository . Interface ;
95using Microsoft . AspNetCore . Builder ;
10- using Microsoft . AspNetCore . Hosting ;
11- using Microsoft . AspNetCore . HttpsPolicy ;
12- using Microsoft . AspNetCore . Mvc ;
13- using Microsoft . EntityFrameworkCore ;
6+ using Microsoft . AspNetCore . Hosting ;
147using Microsoft . Extensions . Configuration ;
158using Microsoft . Extensions . DependencyInjection ;
169using Microsoft . Extensions . Hosting ;
17- using Microsoft . Extensions . Logging ;
1810using Microsoft . OpenApi . Models ;
1911
2012namespace Facware . Api
@@ -31,18 +23,36 @@ public Startup(IConfiguration configuration)
3123 // This method gets called by the runtime. Use this method to add services to the container.
3224 public void ConfigureServices ( IServiceCollection services )
3325 {
26+ #region Swagger service
27+ // enable swagger service
28+ services . ConfigureSwaggerExtension ( _configuration ) ;
29+ #endregion
3430
3531 services . AddControllers ( ) ;
36- services . AddSwaggerGen ( c =>
32+ /* services.AddSwaggerGen(c =>
3733 {
3834 c.SwaggerDoc("v1", new OpenApiInfo { Title = "Facware.Api", Version = "v1" });
39- } ) ;
35+ });*/
4036
41- var connectionString = _configuration [ "DbContextSettings:ConnectionString" ] ;
42- services . AddDbContext < FacwareDbContext > ( options =>
37+ // var connectionString = _configuration["DbContextSettings:ConnectionString"];
38+ /* services.AddDbContext<FacwareDbContext>(options =>
4339 options.UseNpgsql(
4440 connectionString,
45- x => x . MigrationsAssembly ( "Facware.Data.Access" ) ) ) ;
41+ x => x.MigrationsAssembly("Facware.Data.Access"))); */
42+
43+
44+ #region Database context service
45+ // TODO: before use this, create your own dbcontext
46+ services . UsePostgreSqlServer ( _configuration ) ;
47+
48+ // in memory db
49+ // services.UseInMemoryDatabase();
50+ #endregion
51+
52+ #region Cors service
53+ // enable policy cors service
54+ services . ConfigureCors ( _configuration ) ;
55+ #endregion
4656
4757 services . AddTransient ( typeof ( IGenericRepository < > ) , typeof ( GenericRepository < > ) ) ;
4858 services . AddTransient < IItemRepository , ItemRepository > ( ) ;
@@ -52,11 +62,26 @@ public void ConfigureServices(IServiceCollection services)
5262 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
5363 public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
5464 {
55- if ( env . IsDevelopment ( ) )
56- {
57- app . UseDeveloperExceptionPage ( ) ;
58- app . UseSwagger ( ) ;
59- app . UseSwaggerUI ( c => c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "Facware.Api v1" ) ) ;
65+ // Cors pipe
66+ app . UseCors ( CorsExtension . AllowSpecificOrigins ) ;
67+ // handle several environments
68+ if ( env . IsLocal ( ) )
69+ {
70+ app . UseDeveloperExceptionPage ( ) ;
71+ app . EnableSwaggerPipeline ( _configuration ) ;
72+ }
73+ else if ( env . IsDevelopment ( ) )
74+ {
75+ app . UseDeveloperExceptionPage ( ) ;
76+ app . EnableSwaggerPipeline ( _configuration ) ;
77+ }
78+ else if ( env . IsStaging ( ) )
79+ {
80+ app . EnableSwaggerPipeline ( _configuration ) ;
81+ }
82+ else
83+ {
84+ app . EnableSwaggerPipeline ( _configuration ) ;
6085 }
6186
6287 app . UseHttpsRedirection ( ) ;
0 commit comments