Browse Source

More clean up

- Make the catalog API runnable
- Delete some cruft
davidfowl/common-services
David Fowler 1 year ago
committed by Reuben Bond
parent
commit
0fd20ee962
10 changed files with 50 additions and 118 deletions
  1. +1
    -1
      src/Services/Catalog/Catalog.API/Catalog.API.csproj
  2. +7
    -8
      src/Services/Catalog/Catalog.API/CustomExtensionMethods.cs
  3. +0
    -4
      src/Services/Catalog/Catalog.API/GlobalUsings.cs
  4. +0
    -10
      src/Services/Catalog/Catalog.API/Infrastructure/ActionResults/InternalServerErrorObjectResult.cs
  5. +0
    -58
      src/Services/Catalog/Catalog.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs
  6. +2
    -7
      src/Services/Catalog/Catalog.API/Program.cs
  7. +2
    -20
      src/Services/Catalog/Catalog.API/Properties/launchSettings.json
  8. +14
    -0
      src/Services/Catalog/Catalog.API/Properties/serviceDependencies.json
  9. +23
    -0
      src/Services/Catalog/Catalog.API/Properties/serviceDependencies.local.json
  10. +1
    -10
      src/Services/Catalog/Catalog.API/appsettings.json

+ 1
- 1
src/Services/Catalog/Catalog.API/Catalog.API.csproj View File

@ -38,7 +38,7 @@
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="Catalog.FunctionalTests"/>
<InternalsVisibleTo Include="Catalog.FunctionalTests" />
</ItemGroup>
<ItemGroup>


+ 7
- 8
src/Services/Catalog/Catalog.API/CustomExtensionMethods.cs View File

@ -12,7 +12,7 @@ public static class CustomExtensionMethods
.AddSqlServer(
connectionString,
name: "CatalogDB-check",
tags: new string[] { "catalogdb" });
tags: new string[] { "live", "ready" });
}
var accountName = configuration["AzureStorageAccountName"];
@ -24,7 +24,7 @@ public static class CustomExtensionMethods
.AddAzureBlobStorage(
$"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accountKey};EndpointSuffix=core.windows.net",
name: "catalog-storage-check",
tags: new string[] { "catalogstorage" });
tags: new string[] { "live", "ready" });
}
return services;
@ -41,13 +41,12 @@ public static class CustomExtensionMethods
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
};
services.AddEntityFrameworkSqlServer()
.AddDbContext<CatalogContext>(options =>
{
var connectionString = configuration.GetRequiredConnectionString("CatalogDB");
services.AddDbContext<CatalogContext>(options =>
{
var connectionString = configuration.GetRequiredConnectionString("CatalogDB");
options.UseSqlServer(connectionString, ConfigureSqlOptions);
});
options.UseSqlServer(connectionString, ConfigureSqlOptions);
});
services.AddDbContext<IntegrationEventLogContext>(options =>
{


+ 0
- 4
src/Services/Catalog/Catalog.API/GlobalUsings.cs View File

@ -14,7 +14,6 @@ global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore.Mvc.Filters;
global using Microsoft.EntityFrameworkCore;
global using Microsoft.EntityFrameworkCore.Design;
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.Grpc;
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.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.EventHandling;
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.DependencyInjection;
global using Microsoft.Extensions.FileProviders;
global using Microsoft.Extensions.Hosting;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
global using Polly;


+ 0
- 10
src/Services/Catalog/Catalog.API/Infrastructure/ActionResults/InternalServerErrorObjectResult.cs View File

@ -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;
}
}

+ 0
- 58
src/Services/Catalog/Catalog.API/Infrastructure/Filters/HttpGlobalExceptionFilter.cs View File

@ -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; }
}
}

+ 2
- 7
src/Services/Catalog/Catalog.API/Program.cs View File

@ -4,14 +4,10 @@ var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.Services.AddControllers(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
})
.AddJsonOptions(options => options.JsonSerializerOptions.WriteIndented = true);
builder.Services.AddGrpc();
builder.Services.AddControllers();
// Applcation specific services
builder.Services.AddDbContexts(builder.Configuration);
builder.Services.AddApplicationOptions(builder.Configuration);
builder.Services.AddHealthChecks(builder.Configuration);
@ -33,7 +29,6 @@ app.UseFileServer(new FileServerOptions
app.MapGet("/", () => Results.Redirect("/swagger"));
app.MapControllers();
app.MapGrpcService<CatalogService>();
var eventBus = app.Services.GetRequiredService<IEventBus>();


+ 2
- 20
src/Services/Catalog/Catalog.API/Properties/launchSettings.json View File

@ -1,27 +1,9 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:57424/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"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": {
"Catalog.API": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:55101/",
"applicationUrl": "http://localhost:5226/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}


+ 14
- 0
src/Services/Catalog/Catalog.API/Properties/serviceDependencies.json View File

@ -0,0 +1,14 @@
{
"dependencies": {
"rabbitmq1": {
"type": "rabbitmq",
"connectionId": "ConnectionStrings:EventBus",
"dynamicId": null
},
"mssql1": {
"type": "mssql",
"connectionId": "ConnectionStrings:CatalogDB",
"dynamicId": null
}
}
}

+ 23
- 0
src/Services/Catalog/Catalog.API/Properties/serviceDependencies.local.json View File

@ -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
}
}
}

+ 1
- 10
src/Services/Catalog/Catalog.API/appsettings.json View File

@ -5,20 +5,11 @@
"ApplicationInsights": {
"InstrumentationKey": ""
},
"Identity": {
"Url": "http://localhost:5105",
"ExternalUrl": "http://localhost:5105",
"Audience": "catalog",
"Scopes": {
"catalog": "Catalog API"
}
},
"OpenApi": {
"Endpoint": {
"Name": ""
"Name": "Catalog.API V1"
},
"Document": {
"Name": "Catalog.API V1",
"Description": "The Catalog Microservice HTTP API. This is a Data-Driven/CRUD microservice sample",
"Title": "eShopOnContainers - Catalog HTTP API",
"Version": "v1"


Loading…
Cancel
Save