fix routing

This commit is contained in:
Erik Pique 2019-07-26 09:42:43 +02:00
parent 5f9a1b8b8f
commit 8b0ec9038f
5 changed files with 18 additions and 30 deletions

View File

@ -49,17 +49,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
{ {
RegisterAppInsights(services); RegisterAppInsights(services);
// Add framework services.
//services.AddMvc(options =>
// {
// options.Filters.Add(typeof(HttpGlobalExceptionFilter));
// options.Filters.Add(typeof(ValidateModelStateFilter));
// })
// .AddNewtonsoftJson()
// .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
// .AddControllersAsServices();
services.AddControllers(options => services.AddControllers(options =>
{ {
options.Filters.Add(typeof(HttpGlobalExceptionFilter)); options.Filters.Add(typeof(HttpGlobalExceptionFilter));
@ -204,10 +193,12 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
ConfigureAuth(app); ConfigureAuth(app);
app.UseAuthorization();
app.UseRouting(); app.UseRouting();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
endpoints.MapDefaultControllerRoute(); endpoints.MapDefaultControllerRoute();
endpoints.MapControllers();
endpoints.MapHealthChecks("/hc", new HealthCheckOptions() endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{ {
Predicate = _ => true, Predicate = _ => true,

View File

@ -55,8 +55,6 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
.AddSwagger() .AddSwagger()
.AddCustomHealthCheck(Configuration); .AddCustomHealthCheck(Configuration);
services.AddControllers();
var container = new ContainerBuilder(); var container = new ContainerBuilder();
container.Populate(services); container.Populate(services);
@ -139,11 +137,13 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
public static IServiceCollection AddCustomMVC(this IServiceCollection services, IConfiguration configuration) public static IServiceCollection AddCustomMVC(this IServiceCollection services, IConfiguration configuration)
{ {
services.AddMvc(options => services.AddMvc(options =>
{ {
options.Filters.Add(typeof(HttpGlobalExceptionFilter)); options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}) })
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddControllersAsServices(); .AddControllersAsServices();
services.AddControllers();
services.AddCors(options => services.AddCors(options =>
{ {

View File

@ -51,7 +51,11 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddControllersAsServices(); .AddControllersAsServices();
services.AddControllers(); services.AddControllers(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
}).AddNewtonsoftJson();
ConfigureAuthService(services); ConfigureAuthService(services);

View File

@ -23,7 +23,6 @@
using Marketing.API.IntegrationEvents.Handlers; using Marketing.API.IntegrationEvents.Handlers;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares; using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Middlewares;
using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Diagnostics.HealthChecks;
@ -50,15 +49,7 @@
RegisterAppInsights(services); RegisterAppInsights(services);
// Add framework services. // Add framework services.
services services.AddCustomHealthCheck(Configuration);
.AddCustomHealthCheck(Configuration)
.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddControllersAsServices(); //Injecting Controllers themselves thru DIFor further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
services.AddControllers(); services.AddControllers();
services.Configure<MarketingSettings>(Configuration); services.Configure<MarketingSettings>(Configuration);
@ -198,10 +189,12 @@
ConfigureAuth(app); ConfigureAuth(app);
app.UseAuthorization();
app.UseRouting(); app.UseRouting();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
endpoints.MapDefaultControllerRoute(); endpoints.MapDefaultControllerRoute();
endpoints.MapControllers();
endpoints.MapHealthChecks("/hc", new HealthCheckOptions() endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{ {
Predicate = _ => true, Predicate = _ => true,

View File

@ -72,7 +72,7 @@
<Microsoft_EntityFrameworkCore_SqlServer>3.0.0-preview7.19362.6</Microsoft_EntityFrameworkCore_SqlServer> <Microsoft_EntityFrameworkCore_SqlServer>3.0.0-preview7.19362.6</Microsoft_EntityFrameworkCore_SqlServer>
<Microsoft_EntityFrameworkCore_Design>3.0.0-preview7.19362.6</Microsoft_EntityFrameworkCore_Design> <Microsoft_EntityFrameworkCore_Design>3.0.0-preview7.19362.6</Microsoft_EntityFrameworkCore_Design>
<Microsoft_Extensions_Identity_Stores>3.0.0-preview7.19365.7</Microsoft_Extensions_Identity_Stores> <Microsoft_Extensions_Identity_Stores>3.0.0-preview7.19365.7</Microsoft_Extensions_Identity_Stores>
<Microsoft_Extensions_Configuration_AzureKeyVault>2.2.0</Microsoft_Extensions_Configuration_AzureKeyVault> <Microsoft_Extensions_Configuration_AzureKeyVault>3.0.0-preview7.19362.4</Microsoft_Extensions_Configuration_AzureKeyVault>
<Microsoft_Extensions_DependencyInjection_Abstractions>2.2.0</Microsoft_Extensions_DependencyInjection_Abstractions> <Microsoft_Extensions_DependencyInjection_Abstractions>2.2.0</Microsoft_Extensions_DependencyInjection_Abstractions>
<Microsoft_Extensions_Diagnostics_HealthChecks>2.2.0</Microsoft_Extensions_Diagnostics_HealthChecks> <Microsoft_Extensions_Diagnostics_HealthChecks>2.2.0</Microsoft_Extensions_Diagnostics_HealthChecks>
<Microsoft_Extensions_Http>2.2.0</Microsoft_Extensions_Http> <Microsoft_Extensions_Http>2.2.0</Microsoft_Extensions_Http>