1
- using AutoMapper ;
2
- using Microsoft . AspNetCore . Builder ;
1
+ using Microsoft . AspNetCore . Builder ;
3
2
using Microsoft . AspNetCore . Hosting ;
3
+ using Microsoft . AspNetCore . HttpOverrides ;
4
4
using Microsoft . AspNetCore . Mvc ;
5
- using Microsoft . EntityFrameworkCore ;
6
5
using Microsoft . Extensions . Configuration ;
7
6
using Microsoft . Extensions . DependencyInjection ;
8
- using Supermarket . Domain . Services ;
9
- using Supermarket . Domain . Services . Contracts ;
10
- using Supermarket . Persistent . Context ;
11
- using Supermarket . Persistent . Contracts ;
12
- using Supermarket . Persistent . Repositories ;
7
+ using Newtonsoft . Json . Serialization ;
8
+ using Supermarket . Extensions ;
9
+ using Swashbuckle . AspNetCore . Swagger ;
13
10
14
11
namespace Supermarket
15
12
{
@@ -25,17 +22,25 @@ public Startup(IConfiguration configuration)
25
22
// This method gets called by the runtime. Use this method to add services to the container.
26
23
public void ConfigureServices ( IServiceCollection services )
27
24
{
28
- services . AddMvc ( ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_2 ) ;
25
+ services . ConfigureCors ( ) ;
29
26
30
- services . AddDbContext < RepositoryContext > ( options =>
27
+ services . ConfigureIISIntegration ( ) ;
28
+
29
+ services . ConfigureMSSQLContext ( Configuration ) ;
30
+
31
+ services . ConfigureRepositoryWrapper ( ) ;
32
+
33
+ services . ConfigureServicesWrapper ( ) ;
34
+
35
+ services . AddMvc ( ) . AddJsonOptions ( options =>
31
36
{
32
- options . UseInMemoryDatabase ( "supermarket-api-in-memory" ) ;
33
- } ) ;
37
+ //Force Camel Case to JSON
38
+ options . SerializerSettings . ContractResolver = new CamelCasePropertyNamesContractResolver ( ) ;
39
+ } ) . SetCompatibilityVersion ( CompatibilityVersion . Version_2_2 ) ;
34
40
35
- services . AddScoped < IRepositoryWrapper , RepositoryWrapper > ( ) ;
36
- services . AddScoped < IServiceWrapper , ServiceWrapper > ( ) ;
41
+ services . ConfigureAutoMapper ( ) ;
37
42
38
- services . AddAutoMapper ( ) ;
43
+ services . ConfigureSwagger ( ) ;
39
44
}
40
45
41
46
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -52,7 +57,27 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
52
57
}
53
58
54
59
app . UseHttpsRedirection ( ) ;
60
+
61
+ //CORS configuration has beend added to the application pipeline
62
+ app . UseCors ( "CorsPolicy" ) ;
63
+
64
+ app . UseForwardedHeaders ( new ForwardedHeadersOptions
65
+ {
66
+ ForwardedHeaders = ForwardedHeaders . All
67
+ } ) ;
68
+
69
+ app . UseStaticFiles ( ) ;
55
70
app . UseMvc ( ) ;
71
+
72
+ // Enable middleware to serve generated Swagger as a JSON endpoint.
73
+ app . UseSwagger ( ) ;
74
+
75
+ // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
76
+ // specifying the Swagger JSON endpoint.
77
+ app . UseSwaggerUI ( c =>
78
+ {
79
+ c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "Supermarket API V1" ) ;
80
+ } ) ;
56
81
}
57
82
}
58
83
}
0 commit comments