2323 using Marketing . API . IntegrationEvents . Handlers ;
2424 using Microsoft . AspNetCore . Authentication . JwtBearer ;
2525 using Microsoft . AspNetCore . Diagnostics . HealthChecks ;
26+ using Microsoft . AspNetCore . Mvc ;
2627 using Microsoft . EntityFrameworkCore . Diagnostics ;
28+ using Microsoft . eShopOnContainers . Services . Marketing . API . Controllers ;
2729 using Microsoft . eShopOnContainers . Services . Marketing . API . Infrastructure . Middlewares ;
2830 using Microsoft . Extensions . Diagnostics . HealthChecks ;
2931 using Microsoft . OpenApi . Models ;
@@ -44,13 +46,18 @@ public Startup(IConfiguration configuration)
4446
4547
4648 // This method gets called by the runtime. Use this method to add services to the container.
47- public IServiceProvider ConfigureServices ( IServiceCollection services )
49+ public virtual IServiceProvider ConfigureServices ( IServiceCollection services )
4850 {
4951 RegisterAppInsights ( services ) ;
5052
5153 // Add framework services.
5254 services . AddCustomHealthCheck ( Configuration ) ;
53- services . AddControllers ( ) . AddNewtonsoftJson ( ) ;
55+ services
56+ . AddControllers ( )
57+ // Added for functional tests
58+ . AddApplicationPart ( typeof ( LocationsController ) . Assembly )
59+ . AddNewtonsoftJson ( )
60+ . SetCompatibilityVersion ( CompatibilityVersion . Version_3_0 ) ;
5461 services . Configure < MarketingSettings > ( Configuration ) ;
5562
5663 ConfigureAuthService ( services ) ;
@@ -117,36 +124,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
117124 }
118125
119126 // Add framework services.
120- services . AddSwaggerGen ( options =>
121- {
122- options . DescribeAllEnumsAsStrings ( ) ;
123- options . SwaggerDoc ( "v1" , new OpenApiInfo
124- {
125- Title = "eShopOnContainers - Marketing HTTP API" ,
126- Version = "v1" ,
127- Description = "The Marketing Service HTTP API"
128- } ) ;
129-
130- options . AddSecurityDefinition ( "oauth2" , new OpenApiSecurityScheme
131- {
132- Type = SecuritySchemeType . OAuth2 ,
133- Flows = new OpenApiOAuthFlows ( )
134- {
135- Implicit = new OpenApiOAuthFlow ( )
136- {
137- AuthorizationUrl = new Uri ( $ "{ Configuration . GetValue < string > ( "IdentityUrlExternal" ) } /connect/authorize") ,
138- TokenUrl = new Uri ( $ "{ Configuration . GetValue < string > ( "IdentityUrlExternal" ) } /connect/token") ,
139- Scopes = new Dictionary < string , string > ( )
140- {
141- { "marketing" , "Marketing API" }
142- }
143- }
144- }
145- } ) ;
146-
147- options . OperationFilter < AuthorizeCheckOperationFilter > ( ) ;
148- } ) ;
149127
128+ AddCustomSwagger ( services ) ;
150129 services . AddCors ( options =>
151130 {
152131 options . AddPolicy ( "CorsPolicy" ,
@@ -186,10 +165,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
186165 }
187166
188167 app . UseCors ( "CorsPolicy" ) ;
168+ app . UseRouting ( ) ;
189169
190170 ConfigureAuth ( app ) ;
191171
192- app . UseRouting ( ) ;
193172 app . UseEndpoints ( endpoints =>
194173 {
195174 endpoints . MapDefaultControllerRoute ( ) ;
@@ -216,6 +195,39 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
216195 ConfigureEventBus ( app ) ;
217196 }
218197
198+ private void AddCustomSwagger ( IServiceCollection services )
199+ {
200+ services . AddSwaggerGen ( options =>
201+ {
202+ options . DescribeAllEnumsAsStrings ( ) ;
203+ options . SwaggerDoc ( "v1" , new OpenApiInfo
204+ {
205+ Title = "eShopOnContainers - Marketing HTTP API" ,
206+ Version = "v1" ,
207+ Description = "The Marketing Service HTTP API"
208+ } ) ;
209+
210+ options . AddSecurityDefinition ( "oauth2" , new OpenApiSecurityScheme
211+ {
212+ Type = SecuritySchemeType . OAuth2 ,
213+ Flows = new OpenApiOAuthFlows ( )
214+ {
215+ Implicit = new OpenApiOAuthFlow ( )
216+ {
217+ AuthorizationUrl = new Uri ( $ "{ Configuration . GetValue < string > ( "IdentityUrlExternal" ) } /connect/authorize") ,
218+ TokenUrl = new Uri ( $ "{ Configuration . GetValue < string > ( "IdentityUrlExternal" ) } /connect/token") ,
219+ Scopes = new Dictionary < string , string > ( )
220+ {
221+ { "marketing" , "Marketing API" }
222+ }
223+ }
224+ }
225+ } ) ;
226+
227+ options . OperationFilter < AuthorizeCheckOperationFilter > ( ) ;
228+ } ) ;
229+ }
230+
219231 private void RegisterAppInsights ( IServiceCollection services )
220232 {
221233 services . AddApplicationInsightsTelemetry ( Configuration ) ;
@@ -225,7 +237,7 @@ private void RegisterAppInsights(IServiceCollection services)
225237 private void ConfigureAuthService ( IServiceCollection services )
226238 {
227239 // prevent from mapping "sub" claim to nameidentifier.
228- JwtSecurityTokenHandler . DefaultInboundClaimTypeMap . Clear ( ) ;
240+ JwtSecurityTokenHandler . DefaultInboundClaimTypeMap . Remove ( "sub" ) ;
229241
230242 services . AddAuthentication ( options =>
231243 {
0 commit comments