Browse Source

change startup routing

features/migration-dotnet3
Erik Pique 5 years ago
parent
commit
0a0b013b73
4 changed files with 47 additions and 38 deletions
  1. +24
    -9
      src/Services/Catalog/Catalog.API/Startup.cs
  2. +3
    -9
      src/Services/Location/Locations.API/Startup.cs
  3. +13
    -10
      src/Services/Ordering/Ordering.API/Startup.cs
  4. +7
    -10
      src/Services/Webhooks/Webhooks.API/Startup.cs

+ 24
- 9
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -26,8 +26,10 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.IO;
using System.Reflection;
@ -52,7 +54,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
.AddCustomOptions(Configuration)
.AddIntegrationServices(Configuration)
.AddEventBus(Configuration)
.AddSwagger()
.AddSwagger(Configuration)
.AddCustomHealthCheck(Configuration);
var container = new ContainerBuilder();
@ -76,11 +78,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
}
app.UseCors("CorsPolicy");
app.UseAuthorization();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapControllers();
endpoints.MapGet("/_proto/", async ctx =>
{
ctx.Response.ContentType = "text/plain";
@ -136,14 +139,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
public static IServiceCollection AddCustomMVC(this IServiceCollection services, IConfiguration configuration)
{
services.AddMvc(options =>
services.AddControllers(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddControllersAsServices();
services.AddControllers();
});
services.AddCors(options =>
{
@ -259,7 +258,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
return services;
}
public static IServiceCollection AddSwagger(this IServiceCollection services)
public static IServiceCollection AddSwagger(this IServiceCollection services, IConfiguration configuration)
{
services.AddSwaggerGen(options =>
{
@ -270,6 +269,22 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
Version = "v1",
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;


+ 3
- 9
src/Services/Location/Locations.API/Startup.cs View File

@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
@ -42,14 +41,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
{
RegisterAppInsights(services);
services
.AddCustomHealthCheck(Configuration)
.AddMvc(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddControllersAsServices();
services.AddCustomHealthCheck(Configuration);
services.AddControllers(options =>
{
@ -177,10 +169,12 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API
ConfigureAuth(app);
app.UseAuthorization();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapControllers();
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,


+ 13
- 10
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -55,9 +55,6 @@
.AddCustomConfiguration(Configuration)
.AddEventBus(Configuration)
.AddCustomAuthentication(Configuration);
services.AddControllers();
//configure autofac
var container = new ContainerBuilder();
@ -86,10 +83,12 @@
ConfigureAuth(app);
app.UseAuthorization();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapControllers();
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
@ -149,13 +148,17 @@
public static IServiceCollection AddCustomMvc(this IServiceCollection services)
{
// Add framework services.
services.AddMvc(options =>
{
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.AddControllers(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
});
//services.AddMvc(options =>
// {
// 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 =>
{


+ 7
- 10
src/Services/Webhooks/Webhooks.API/Startup.cs View File

@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
@ -47,7 +46,7 @@ namespace Webhooks.API
{
services
.AddAppInsight(Configuration)
.AddCustomMVC(Configuration)
.AddCustomRouting(Configuration)
.AddCustomDbContext(Configuration)
.AddSwagger(Configuration)
.AddCustomHealthCheck(Configuration)
@ -62,8 +61,6 @@ namespace Webhooks.API
.AddTransient<IWebhooksRetriever, WebhooksRetriever>()
.AddTransient<IWebhooksSender, WebhooksSender>();
services.AddControllers();
var container = new ContainerBuilder();
container.Populate(services);
return new AutofacServiceProvider(container.Build());
@ -85,10 +82,12 @@ namespace Webhooks.API
ConfigureAuth(app);
app.UseAuthorization();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapControllers();
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()
{
Predicate = _ => true,
@ -142,14 +141,12 @@ namespace Webhooks.API
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));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddControllersAsServices();
});
services.AddCors(options =>
{
@ -209,7 +206,7 @@ namespace Webhooks.API
TokenUrl = new Uri($"{configuration.GetValue<string>("IdentityUrlExternal")}/connect/token"),
Scopes = new Dictionary<string, string>()
{
{ "marketing", "Marketing API" }
{ "webhooks", "Webhooks API" }
}
}
}


Loading…
Cancel
Save