change startup routing
This commit is contained in:
parent
8b0ec9038f
commit
0a0b013b73
@ -26,8 +26,10 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
using RabbitMQ.Client;
|
using RabbitMQ.Client;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -52,7 +54,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
|||||||
.AddCustomOptions(Configuration)
|
.AddCustomOptions(Configuration)
|
||||||
.AddIntegrationServices(Configuration)
|
.AddIntegrationServices(Configuration)
|
||||||
.AddEventBus(Configuration)
|
.AddEventBus(Configuration)
|
||||||
.AddSwagger()
|
.AddSwagger(Configuration)
|
||||||
.AddCustomHealthCheck(Configuration);
|
.AddCustomHealthCheck(Configuration);
|
||||||
|
|
||||||
var container = new ContainerBuilder();
|
var container = new ContainerBuilder();
|
||||||
@ -76,11 +78,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.UseCors("CorsPolicy");
|
app.UseCors("CorsPolicy");
|
||||||
|
app.UseAuthorization();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapDefaultControllerRoute();
|
endpoints.MapDefaultControllerRoute();
|
||||||
|
endpoints.MapControllers();
|
||||||
endpoints.MapGet("/_proto/", async ctx =>
|
endpoints.MapGet("/_proto/", async ctx =>
|
||||||
{
|
{
|
||||||
ctx.Response.ContentType = "text/plain";
|
ctx.Response.ContentType = "text/plain";
|
||||||
@ -136,14 +139,10 @@ 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.AddControllers(options =>
|
||||||
{
|
{
|
||||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||||
})
|
});
|
||||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
|
|
||||||
.AddControllersAsServices();
|
|
||||||
|
|
||||||
services.AddControllers();
|
|
||||||
|
|
||||||
services.AddCors(options =>
|
services.AddCors(options =>
|
||||||
{
|
{
|
||||||
@ -259,7 +258,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddSwagger(this IServiceCollection services)
|
public static IServiceCollection AddSwagger(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.AddSwaggerGen(options =>
|
services.AddSwaggerGen(options =>
|
||||||
{
|
{
|
||||||
@ -270,6 +269,22 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
|||||||
Version = "v1",
|
Version = "v1",
|
||||||
Description = "The Catalog Microservice HTTP API. This is a Data-Driven/CRUD microservice sample"
|
Description = "The Catalog Microservice HTTP API. This is a Data-Driven/CRUD microservice sample"
|
||||||
});
|
});
|
||||||
|
options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Type = SecuritySchemeType.OAuth2,
|
||||||
|
Flows = new OpenApiOAuthFlows()
|
||||||
|
{
|
||||||
|
Implicit = new OpenApiOAuthFlow()
|
||||||
|
{
|
||||||
|
AuthorizationUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize"),
|
||||||
|
TokenUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
|
||||||
|
Scopes = new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "catalog", "Catalog API" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
|
@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Builder;
|
|||||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Azure.ServiceBus;
|
using Microsoft.Azure.ServiceBus;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||||
@ -42,14 +41,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
|
|||||||
{
|
{
|
||||||
RegisterAppInsights(services);
|
RegisterAppInsights(services);
|
||||||
|
|
||||||
services
|
services.AddCustomHealthCheck(Configuration);
|
||||||
.AddCustomHealthCheck(Configuration)
|
|
||||||
.AddMvc(options =>
|
|
||||||
{
|
|
||||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
|
||||||
})
|
|
||||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
|
|
||||||
.AddControllersAsServices();
|
|
||||||
|
|
||||||
services.AddControllers(options =>
|
services.AddControllers(options =>
|
||||||
{
|
{
|
||||||
@ -177,10 +169,12 @@ namespace Microsoft.eShopOnContainers.Services.Locations.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,
|
||||||
|
@ -55,9 +55,6 @@
|
|||||||
.AddCustomConfiguration(Configuration)
|
.AddCustomConfiguration(Configuration)
|
||||||
.AddEventBus(Configuration)
|
.AddEventBus(Configuration)
|
||||||
.AddCustomAuthentication(Configuration);
|
.AddCustomAuthentication(Configuration);
|
||||||
|
|
||||||
services.AddControllers();
|
|
||||||
|
|
||||||
//configure autofac
|
//configure autofac
|
||||||
|
|
||||||
var container = new ContainerBuilder();
|
var container = new ContainerBuilder();
|
||||||
@ -86,10 +83,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,
|
||||||
@ -149,13 +148,17 @@
|
|||||||
public static IServiceCollection AddCustomMvc(this IServiceCollection services)
|
public static IServiceCollection AddCustomMvc(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
// Add framework services.
|
// Add framework services.
|
||||||
services.AddMvc(options =>
|
services.AddControllers(options =>
|
||||||
{
|
{
|
||||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||||
})
|
});
|
||||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
|
//services.AddMvc(options =>
|
||||||
.AddControllersAsServices(); //Injecting Controllers themselves thru DI
|
// {
|
||||||
//For further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
|
// options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||||
|
// })
|
||||||
|
// .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
|
||||||
|
// .AddControllersAsServices(); //Injecting Controllers themselves thru DI
|
||||||
|
// //For further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
|
||||||
|
|
||||||
services.AddCors(options =>
|
services.AddCors(options =>
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Azure.ServiceBus;
|
using Microsoft.Azure.ServiceBus;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
@ -47,7 +46,7 @@ namespace Webhooks.API
|
|||||||
{
|
{
|
||||||
services
|
services
|
||||||
.AddAppInsight(Configuration)
|
.AddAppInsight(Configuration)
|
||||||
.AddCustomMVC(Configuration)
|
.AddCustomRouting(Configuration)
|
||||||
.AddCustomDbContext(Configuration)
|
.AddCustomDbContext(Configuration)
|
||||||
.AddSwagger(Configuration)
|
.AddSwagger(Configuration)
|
||||||
.AddCustomHealthCheck(Configuration)
|
.AddCustomHealthCheck(Configuration)
|
||||||
@ -62,8 +61,6 @@ namespace Webhooks.API
|
|||||||
.AddTransient<IWebhooksRetriever, WebhooksRetriever>()
|
.AddTransient<IWebhooksRetriever, WebhooksRetriever>()
|
||||||
.AddTransient<IWebhooksSender, WebhooksSender>();
|
.AddTransient<IWebhooksSender, WebhooksSender>();
|
||||||
|
|
||||||
services.AddControllers();
|
|
||||||
|
|
||||||
var container = new ContainerBuilder();
|
var container = new ContainerBuilder();
|
||||||
container.Populate(services);
|
container.Populate(services);
|
||||||
return new AutofacServiceProvider(container.Build());
|
return new AutofacServiceProvider(container.Build());
|
||||||
@ -85,10 +82,12 @@ namespace Webhooks.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,
|
||||||
@ -142,14 +141,12 @@ namespace Webhooks.API
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddCustomMVC(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddCustomRouting(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.AddMvc(options =>
|
services.AddControllers(options =>
|
||||||
{
|
{
|
||||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||||
})
|
});
|
||||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
|
|
||||||
.AddControllersAsServices();
|
|
||||||
|
|
||||||
services.AddCors(options =>
|
services.AddCors(options =>
|
||||||
{
|
{
|
||||||
@ -209,7 +206,7 @@ namespace Webhooks.API
|
|||||||
TokenUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
|
TokenUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
|
||||||
Scopes = new Dictionary<string, string>()
|
Scopes = new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{ "marketing", "Marketing API" }
|
{ "webhooks", "Webhooks API" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user