More clean up
- Make the catalog API runnable - Delete some cruft
This commit is contained in:
parent
34fc9496fd
commit
0fd20ee962
@ -38,7 +38,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<InternalsVisibleTo Include="Catalog.FunctionalTests"/>
|
<InternalsVisibleTo Include="Catalog.FunctionalTests" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -12,7 +12,7 @@ public static class CustomExtensionMethods
|
|||||||
.AddSqlServer(
|
.AddSqlServer(
|
||||||
connectionString,
|
connectionString,
|
||||||
name: "CatalogDB-check",
|
name: "CatalogDB-check",
|
||||||
tags: new string[] { "catalogdb" });
|
tags: new string[] { "live", "ready" });
|
||||||
}
|
}
|
||||||
|
|
||||||
var accountName = configuration["AzureStorageAccountName"];
|
var accountName = configuration["AzureStorageAccountName"];
|
||||||
@ -24,7 +24,7 @@ public static class CustomExtensionMethods
|
|||||||
.AddAzureBlobStorage(
|
.AddAzureBlobStorage(
|
||||||
$"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accountKey};EndpointSuffix=core.windows.net",
|
$"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accountKey};EndpointSuffix=core.windows.net",
|
||||||
name: "catalog-storage-check",
|
name: "catalog-storage-check",
|
||||||
tags: new string[] { "catalogstorage" });
|
tags: new string[] { "live", "ready" });
|
||||||
}
|
}
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
@ -41,13 +41,12 @@ public static class CustomExtensionMethods
|
|||||||
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
|
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
|
||||||
};
|
};
|
||||||
|
|
||||||
services.AddEntityFrameworkSqlServer()
|
services.AddDbContext<CatalogContext>(options =>
|
||||||
.AddDbContext<CatalogContext>(options =>
|
{
|
||||||
{
|
var connectionString = configuration.GetRequiredConnectionString("CatalogDB");
|
||||||
var connectionString = configuration.GetRequiredConnectionString("CatalogDB");
|
|
||||||
|
|
||||||
options.UseSqlServer(connectionString, ConfigureSqlOptions);
|
options.UseSqlServer(connectionString, ConfigureSqlOptions);
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddDbContext<IntegrationEventLogContext>(options =>
|
services.AddDbContext<IntegrationEventLogContext>(options =>
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,6 @@ global using Microsoft.AspNetCore.Builder;
|
|||||||
global using Microsoft.AspNetCore.Hosting;
|
global using Microsoft.AspNetCore.Hosting;
|
||||||
global using Microsoft.AspNetCore.Http;
|
global using Microsoft.AspNetCore.Http;
|
||||||
global using Microsoft.AspNetCore.Mvc;
|
global using Microsoft.AspNetCore.Mvc;
|
||||||
global using Microsoft.AspNetCore.Mvc.Filters;
|
|
||||||
global using Microsoft.EntityFrameworkCore;
|
global using Microsoft.EntityFrameworkCore;
|
||||||
global using Microsoft.EntityFrameworkCore.Design;
|
global using Microsoft.EntityFrameworkCore.Design;
|
||||||
global using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
global using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
@ -27,10 +26,8 @@ global using Microsoft.eShopOnContainers.Services.Catalog.API;
|
|||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.Extensions;
|
global using Microsoft.eShopOnContainers.Services.Catalog.API.Extensions;
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.Grpc;
|
global using Microsoft.eShopOnContainers.Services.Catalog.API.Grpc;
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
|
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.ActionResults;
|
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.EntityConfigurations;
|
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.EntityConfigurations;
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.Exceptions;
|
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.Exceptions;
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.Filters;
|
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents;
|
global using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents;
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling;
|
global using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling;
|
||||||
global using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
|
global using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
|
||||||
@ -39,7 +36,6 @@ global using Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel;
|
|||||||
global using Microsoft.Extensions.Configuration;
|
global using Microsoft.Extensions.Configuration;
|
||||||
global using Microsoft.Extensions.DependencyInjection;
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
global using Microsoft.Extensions.FileProviders;
|
global using Microsoft.Extensions.FileProviders;
|
||||||
global using Microsoft.Extensions.Hosting;
|
|
||||||
global using Microsoft.Extensions.Logging;
|
global using Microsoft.Extensions.Logging;
|
||||||
global using Microsoft.Extensions.Options;
|
global using Microsoft.Extensions.Options;
|
||||||
global using Polly;
|
global using Polly;
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.ActionResults;
|
|
||||||
|
|
||||||
public class InternalServerErrorObjectResult : ObjectResult
|
|
||||||
{
|
|
||||||
public InternalServerErrorObjectResult(object error)
|
|
||||||
: base(error)
|
|
||||||
{
|
|
||||||
StatusCode = StatusCodes.Status500InternalServerError;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.Filters;
|
|
||||||
|
|
||||||
public class HttpGlobalExceptionFilter : IExceptionFilter
|
|
||||||
{
|
|
||||||
private readonly IWebHostEnvironment env;
|
|
||||||
private readonly ILogger<HttpGlobalExceptionFilter> logger;
|
|
||||||
|
|
||||||
public HttpGlobalExceptionFilter(IWebHostEnvironment env, ILogger<HttpGlobalExceptionFilter> logger)
|
|
||||||
{
|
|
||||||
this.env = env;
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnException(ExceptionContext context)
|
|
||||||
{
|
|
||||||
logger.LogError(new EventId(context.Exception.HResult),
|
|
||||||
context.Exception,
|
|
||||||
context.Exception.Message);
|
|
||||||
|
|
||||||
if (context.Exception.GetType() == typeof(CatalogDomainException))
|
|
||||||
{
|
|
||||||
var problemDetails = new ValidationProblemDetails()
|
|
||||||
{
|
|
||||||
Instance = context.HttpContext.Request.Path,
|
|
||||||
Status = StatusCodes.Status400BadRequest,
|
|
||||||
Detail = "Please refer to the errors property for additional details."
|
|
||||||
};
|
|
||||||
|
|
||||||
problemDetails.Errors.Add("DomainValidations", new string[] { context.Exception.Message.ToString() });
|
|
||||||
|
|
||||||
context.Result = new BadRequestObjectResult(problemDetails);
|
|
||||||
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var json = new JsonErrorResponse
|
|
||||||
{
|
|
||||||
Messages = new[] { "An error ocurred." }
|
|
||||||
};
|
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
|
||||||
{
|
|
||||||
json.DeveloperMessage = context.Exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Result = new InternalServerErrorObjectResult(json);
|
|
||||||
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
|
||||||
}
|
|
||||||
context.ExceptionHandled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JsonErrorResponse
|
|
||||||
{
|
|
||||||
public string[] Messages { get; set; }
|
|
||||||
|
|
||||||
public object DeveloperMessage { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,14 +4,10 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
|
|
||||||
builder.AddServiceDefaults();
|
builder.AddServiceDefaults();
|
||||||
|
|
||||||
builder.Services.AddControllers(options =>
|
|
||||||
{
|
|
||||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
|
||||||
})
|
|
||||||
.AddJsonOptions(options => options.JsonSerializerOptions.WriteIndented = true);
|
|
||||||
|
|
||||||
builder.Services.AddGrpc();
|
builder.Services.AddGrpc();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
|
// Applcation specific services
|
||||||
builder.Services.AddDbContexts(builder.Configuration);
|
builder.Services.AddDbContexts(builder.Configuration);
|
||||||
builder.Services.AddApplicationOptions(builder.Configuration);
|
builder.Services.AddApplicationOptions(builder.Configuration);
|
||||||
builder.Services.AddHealthChecks(builder.Configuration);
|
builder.Services.AddHealthChecks(builder.Configuration);
|
||||||
@ -33,7 +29,6 @@ app.UseFileServer(new FileServerOptions
|
|||||||
app.MapGet("/", () => Results.Redirect("/swagger"));
|
app.MapGet("/", () => Results.Redirect("/swagger"));
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.MapGrpcService<CatalogService>();
|
app.MapGrpcService<CatalogService>();
|
||||||
|
|
||||||
var eventBus = app.Services.GetRequiredService<IEventBus>();
|
var eventBus = app.Services.GetRequiredService<IEventBus>();
|
||||||
|
@ -1,27 +1,9 @@
|
|||||||
{
|
{
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:57424/",
|
|
||||||
"sslPort": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"IIS Express": {
|
"Catalog.API": {
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"launchUrl": "/swagger",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ConnectionString": "server=localhost,5433;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
|
||||||
"EventBusConnection": "localhost"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Microsoft.eShopOnContainers.Services.Catalog.API": {
|
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "http://localhost:55101/",
|
"applicationUrl": "http://localhost:5226/",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"rabbitmq1": {
|
||||||
|
"type": "rabbitmq",
|
||||||
|
"connectionId": "ConnectionStrings:EventBus",
|
||||||
|
"dynamicId": null
|
||||||
|
},
|
||||||
|
"mssql1": {
|
||||||
|
"type": "mssql",
|
||||||
|
"connectionId": "ConnectionStrings:CatalogDB",
|
||||||
|
"dynamicId": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"rabbitmq1": {
|
||||||
|
"containerPorts": "5672:5672,15672:15672",
|
||||||
|
"secretStore": "LocalSecretsFile",
|
||||||
|
"containerName": "rabbitmq",
|
||||||
|
"containerImage": "rabbitmq:3-management-alpine",
|
||||||
|
"type": "rabbitmq.container",
|
||||||
|
"connectionId": "ConnectionStrings:EventBus",
|
||||||
|
"dynamicId": null
|
||||||
|
},
|
||||||
|
"mssql1": {
|
||||||
|
"serviceConnectorResourceId": "",
|
||||||
|
"containerPorts": "1434:1433",
|
||||||
|
"secretStore": "LocalSecretsFile",
|
||||||
|
"containerName": "catalog-mssql",
|
||||||
|
"containerImage": "mcr.microsoft.com/mssql/server:2019-latest",
|
||||||
|
"type": "mssql.container",
|
||||||
|
"connectionId": "ConnectionStrings:CatalogDB",
|
||||||
|
"dynamicId": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,20 +5,11 @@
|
|||||||
"ApplicationInsights": {
|
"ApplicationInsights": {
|
||||||
"InstrumentationKey": ""
|
"InstrumentationKey": ""
|
||||||
},
|
},
|
||||||
"Identity": {
|
|
||||||
"Url": "http://localhost:5105",
|
|
||||||
"ExternalUrl": "http://localhost:5105",
|
|
||||||
"Audience": "catalog",
|
|
||||||
"Scopes": {
|
|
||||||
"catalog": "Catalog API"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"OpenApi": {
|
"OpenApi": {
|
||||||
"Endpoint": {
|
"Endpoint": {
|
||||||
"Name": ""
|
"Name": "Catalog.API V1"
|
||||||
},
|
},
|
||||||
"Document": {
|
"Document": {
|
||||||
"Name": "Catalog.API 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",
|
||||||
"Title": "eShopOnContainers - Catalog HTTP API",
|
"Title": "eShopOnContainers - Catalog HTTP API",
|
||||||
"Version": "v1"
|
"Version": "v1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user