merge remote branch into fork
This commit is contained in:
commit
62d4b2bd64
@ -1,8 +1,8 @@
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
# It's important to keep lines from here down to "COPY . ." identical in all Dockerfiles
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Grpc.Core;
|
||||
using Grpc.Core.Interceptors;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastructure
|
||||
@ -30,7 +29,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Infrastruct
|
||||
try
|
||||
{
|
||||
var response = await t;
|
||||
_logger.LogDebug($"Response received: {response}");
|
||||
return response;
|
||||
}
|
||||
catch (RpcException e)
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AssemblyName>Mobile.Shopping.HttpAggregator</AssemblyName>
|
||||
<RootNamespace>Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator</RootNamespace>
|
||||
<DockerComposeProjectPath>..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
@ -15,20 +15,20 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.0.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="3.0.0" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.11.2" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Server.ClientFactory" Version="2.25.0" />
|
||||
<PackageReference Include="Grpc.Core" Version="2.25.0" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.25.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.25.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.1.2" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="3.1.2" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.14.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Server.ClientFactory" Version="2.34.0" />
|
||||
<PackageReference Include="Grpc.Core" Version="2.34.0" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.34.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.34.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0-dev-00834" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,48 +1,32 @@
|
||||
using CatalogApi;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static CatalogApi.Catalog;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly UrlsConfig _urls;
|
||||
private readonly Catalog.CatalogClient _client;
|
||||
|
||||
public CatalogService(HttpClient httpClient, IOptions<UrlsConfig> config)
|
||||
public CatalogService(Catalog.CatalogClient client)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_urls = config.Value;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task<CatalogItem> GetCatalogItemAsync(int id)
|
||||
{
|
||||
|
||||
return await GrpcCallerService.CallService(_urls.Catalog + UrlsConfig.CatalogOperations.GetItemById(id), async channel =>
|
||||
{
|
||||
var client = new CatalogClient(channel);
|
||||
var request = new CatalogItemRequest { Id = id };
|
||||
var response = await client.GetItemByIdAsync(request);
|
||||
return MapToCatalogItemResponse(response);
|
||||
});
|
||||
var request = new CatalogItemRequest { Id = id };
|
||||
var response = await _client.GetItemByIdAsync(request);
|
||||
return MapToCatalogItemResponse(response);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids)
|
||||
{
|
||||
|
||||
return await GrpcCallerService.CallService(_urls.GrpcCatalog, async channel=>
|
||||
{
|
||||
var client = new CatalogClient(channel);
|
||||
var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 };
|
||||
var response = await client.GetItemsByIdsAsync(request);
|
||||
return response.Data.Select(this.MapToCatalogItemResponse);
|
||||
});
|
||||
var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 };
|
||||
var response = await _client.GetItemsByIdsAsync(request);
|
||||
return response.Data.Select(MapToCatalogItemResponse);
|
||||
}
|
||||
|
||||
private CatalogItem MapToCatalogItemResponse(CatalogItemResponse catalogItemResponse)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Devspaces.Support;
|
||||
using CatalogApi;
|
||||
using Devspaces.Support;
|
||||
using GrpcBasket;
|
||||
using GrpcOrdering;
|
||||
using HealthChecks.UI.Client;
|
||||
@ -182,9 +183,6 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
|
||||
//register http services
|
||||
|
||||
services.AddHttpClient<ICatalogService, CatalogService>()
|
||||
.AddDevspacesSupport();
|
||||
|
||||
services.AddHttpClient<IOrderApiClient, OrderApiClient>()
|
||||
.AddDevspacesSupport();
|
||||
|
||||
@ -193,7 +191,7 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
|
||||
public static IServiceCollection AddGrpcServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<GrpcExceptionInterceptor>();
|
||||
services.AddTransient<GrpcExceptionInterceptor>();
|
||||
|
||||
services.AddScoped<IBasketService, BasketService>();
|
||||
|
||||
@ -203,6 +201,14 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator
|
||||
options.Address = new Uri(basketApi);
|
||||
}).AddInterceptor<GrpcExceptionInterceptor>();
|
||||
|
||||
services.AddScoped<ICatalogService, CatalogService>();
|
||||
|
||||
services.AddGrpcClient<Catalog.CatalogClient>((services, options) =>
|
||||
{
|
||||
var catalogApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcCatalog;
|
||||
options.Address = new Uri(catalogApi);
|
||||
}).AddInterceptor<GrpcExceptionInterceptor>();
|
||||
|
||||
services.AddScoped<IOrderingService, OrderingService>();
|
||||
|
||||
services.AddGrpcClient<OrderingGrpc.OrderingGrpcClient>((services, options) =>
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Grpc.Core;
|
||||
using Grpc.Core.Interceptors;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
|
||||
@ -30,7 +29,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Infrastructure
|
||||
try
|
||||
{
|
||||
var response = await t;
|
||||
_logger.LogDebug($"Response received: {response}");
|
||||
return response;
|
||||
}
|
||||
catch (RpcException e)
|
||||
|
@ -1,53 +1,41 @@
|
||||
using CatalogApi;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static CatalogApi.Catalog;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly Catalog.CatalogClient _client;
|
||||
private readonly ILogger<CatalogService> _logger;
|
||||
private readonly UrlsConfig _urls;
|
||||
|
||||
public CatalogService(HttpClient httpClient, ILogger<CatalogService> logger, IOptions<UrlsConfig> config)
|
||||
public CatalogService(Catalog.CatalogClient client, ILogger<CatalogService> logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_client = client;
|
||||
_logger = logger;
|
||||
_urls = config.Value;
|
||||
}
|
||||
|
||||
public async Task<CatalogItem> GetCatalogItemAsync(int id)
|
||||
{
|
||||
return await GrpcCallerService.CallService(_urls.GrpcCatalog, async channel =>
|
||||
{
|
||||
var client = new CatalogClient(channel);
|
||||
var request = new CatalogItemRequest { Id = id };
|
||||
_logger.LogInformation("grpc client created, request = {@request}", request);
|
||||
var response = await client.GetItemByIdAsync(request);
|
||||
_logger.LogInformation("grpc response {@response}", response);
|
||||
return MapToCatalogItemResponse(response);
|
||||
});
|
||||
var request = new CatalogItemRequest { Id = id };
|
||||
_logger.LogInformation("grpc request {@request}", request);
|
||||
var response = await _client.GetItemByIdAsync(request);
|
||||
_logger.LogInformation("grpc response {@response}", response);
|
||||
return MapToCatalogItemResponse(response);
|
||||
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CatalogItem>> GetCatalogItemsAsync(IEnumerable<int> ids)
|
||||
{
|
||||
return await GrpcCallerService.CallService(_urls.GrpcCatalog, async channel =>
|
||||
{
|
||||
var client = new CatalogClient(channel);
|
||||
var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 };
|
||||
_logger.LogInformation("grpc client created, request = {@request}", request);
|
||||
var response = await client.GetItemsByIdsAsync(request);
|
||||
_logger.LogInformation("grpc response {@response}", response);
|
||||
return response.Data.Select(this.MapToCatalogItemResponse);
|
||||
});
|
||||
var request = new CatalogItemsRequest { Ids = string.Join(",", ids), PageIndex = 1, PageSize = 10 };
|
||||
_logger.LogInformation("grpc request {@request}", request);
|
||||
var response = await _client.GetItemsByIdsAsync(request);
|
||||
_logger.LogInformation("grpc response {@response}", response);
|
||||
return response.Data.Select(this.MapToCatalogItemResponse);
|
||||
|
||||
}
|
||||
|
||||
private CatalogItem MapToCatalogItemResponse(CatalogItemResponse catalogItemResponse)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Devspaces.Support;
|
||||
using CatalogApi;
|
||||
using Devspaces.Support;
|
||||
using GrpcBasket;
|
||||
using GrpcOrdering;
|
||||
using HealthChecks.UI.Client;
|
||||
@ -185,9 +186,6 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
|
||||
//register http services
|
||||
|
||||
services.AddHttpClient<ICatalogService, CatalogService>()
|
||||
.AddDevspacesSupport();
|
||||
|
||||
services.AddHttpClient<IOrderApiClient, OrderApiClient>()
|
||||
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>()
|
||||
.AddDevspacesSupport();
|
||||
@ -197,7 +195,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
|
||||
public static IServiceCollection AddGrpcServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<GrpcExceptionInterceptor>();
|
||||
services.AddTransient<GrpcExceptionInterceptor>();
|
||||
|
||||
services.AddScoped<IBasketService, BasketService>();
|
||||
|
||||
@ -207,6 +205,14 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
options.Address = new Uri(basketApi);
|
||||
}).AddInterceptor<GrpcExceptionInterceptor>();
|
||||
|
||||
services.AddScoped<ICatalogService, CatalogService>();
|
||||
|
||||
services.AddGrpcClient<Catalog.CatalogClient>((services, options) =>
|
||||
{
|
||||
var catalogApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcCatalog;
|
||||
options.Address = new Uri(catalogApi);
|
||||
}).AddInterceptor<GrpcExceptionInterceptor>();
|
||||
|
||||
services.AddScoped<IOrderingService, OrderingService>();
|
||||
|
||||
services.AddGrpcClient<OrderingGrpc.OrderingGrpcClient>((services, options) =>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<DebugType>portable</DebugType>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
<AssemblyName>Catalog.API</AssemblyName>
|
||||
@ -42,29 +42,30 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="3.0.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.AzureStorage" Version="3.0.1" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="3.0.3" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.0.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.0.0" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.1" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.11.2" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.25.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.25.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.12.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.12.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.1.1" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="3.2.2" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.AzureStorage" Version="3.3.1" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="3.1.4" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.2.0" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.1.2" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.14.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.34.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.34.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.16.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.1.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.1-dev-00216" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0-dev-00834" />
|
||||
<PackageReference Include="Serilog.Sinks.Http" Version="5.2.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Http" Version="7.2.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" Version="4.1.0-dev-00166" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
||||
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.4.0-beta-24913-02" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
{
|
||||
public class CatalogSettings
|
||||
{
|
||||
public string PicBaseUrl { get;set;}
|
||||
public string PicBaseUrl { get; set; }
|
||||
|
||||
public string EventBusConnection { get; set; }
|
||||
|
||||
public bool UseCustomizationData { get; set; }
|
||||
public bool AzureStorageEnabled { get; set; }
|
||||
public bool AzureStorageEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
# It's important to keep lines from here down to "COPY . ." identical in all Dockerfiles
|
||||
|
@ -1,9 +1,9 @@
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Catalog.API.Extensions;
|
||||
using Catalog.API.Extensions;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
|
||||
using Microsoft.eShopOnContainers.Services.Catalog.API;
|
||||
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@ -12,121 +12,113 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
||||
var configuration = GetConfiguration();
|
||||
|
||||
Log.Logger = CreateSerilogLogger(configuration);
|
||||
|
||||
try
|
||||
{
|
||||
public class Program
|
||||
Log.Information("Configuring web host ({ApplicationContext})...", Program.AppName);
|
||||
var host = CreateHostBuilder(configuration, args);
|
||||
|
||||
Log.Information("Applying migrations ({ApplicationContext})...", Program.AppName);
|
||||
host.MigrateDbContext<CatalogContext>((context, services) =>
|
||||
{
|
||||
public static readonly string Namespace = typeof(Program).Namespace;
|
||||
public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
|
||||
var env = services.GetService<IWebHostEnvironment>();
|
||||
var settings = services.GetService<IOptions<CatalogSettings>>();
|
||||
var logger = services.GetService<ILogger<CatalogContextSeed>>();
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
var configuration = GetConfiguration();
|
||||
new CatalogContextSeed()
|
||||
.SeedAsync(context, env, settings, logger)
|
||||
.Wait();
|
||||
})
|
||||
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
|
||||
|
||||
Log.Logger = CreateSerilogLogger(configuration);
|
||||
Log.Information("Starting web host ({ApplicationContext})...", Program.AppName);
|
||||
host.Run();
|
||||
|
||||
try
|
||||
{
|
||||
Log.Information("Configuring web host ({ApplicationContext})...", AppName);
|
||||
var host = CreateHostBuilder(configuration, args);
|
||||
|
||||
Log.Information("Applying migrations ({ApplicationContext})...", AppName);
|
||||
host.MigrateDbContext<CatalogContext>((context, services) =>
|
||||
{
|
||||
var env = services.GetService<IWebHostEnvironment>();
|
||||
var settings = services.GetService<IOptions<CatalogSettings>>();
|
||||
var logger = services.GetService<ILogger<CatalogContextSeed>>();
|
||||
|
||||
new CatalogContextSeed()
|
||||
.SeedAsync(context, env, settings, logger)
|
||||
.Wait();
|
||||
})
|
||||
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
|
||||
|
||||
Log.Information("Starting web host ({ApplicationContext})...", AppName);
|
||||
host.Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName);
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
}
|
||||
|
||||
private static IWebHost CreateHostBuilder(IConfiguration configuration, string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
|
||||
.CaptureStartupErrors(false)
|
||||
.ConfigureKestrel(options =>
|
||||
{
|
||||
var ports = GetDefinedPorts(configuration);
|
||||
options.Listen(IPAddress.Any, ports.httpPort, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
|
||||
});
|
||||
options.Listen(IPAddress.Any, ports.grpcPort, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http2;
|
||||
});
|
||||
|
||||
})
|
||||
.UseStartup<Startup>()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseWebRoot("Pics")
|
||||
.UseSerilog()
|
||||
.Build();
|
||||
|
||||
private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
||||
{
|
||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
||||
return new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.Enrich.WithProperty("ApplicationContext", AppName)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl)
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.CreateLogger();
|
||||
}
|
||||
|
||||
private static (int httpPort, int grpcPort) GetDefinedPorts(IConfiguration config)
|
||||
{
|
||||
var grpcPort = config.GetValue("GRPC_PORT", 81);
|
||||
var port = config.GetValue("PORT", 80);
|
||||
return (port, grpcPort);
|
||||
}
|
||||
|
||||
private static IConfiguration GetConfiguration()
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
var config = builder.Build();
|
||||
|
||||
if (config.GetValue<bool>("UseVault", false))
|
||||
{
|
||||
builder.AddAzureKeyVault(
|
||||
$"https://{config["Vault:Name"]}.vault.azure.net/",
|
||||
config["Vault:ClientId"],
|
||||
config["Vault:ClientSecret"]);
|
||||
}
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName);
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
|
||||
IWebHost CreateHostBuilder(IConfiguration configuration, string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
|
||||
.CaptureStartupErrors(false)
|
||||
.ConfigureKestrel(options =>
|
||||
{
|
||||
var ports = GetDefinedPorts(configuration);
|
||||
options.Listen(IPAddress.Any, ports.httpPort, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
|
||||
});
|
||||
options.Listen(IPAddress.Any, ports.grpcPort, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http2;
|
||||
});
|
||||
|
||||
})
|
||||
.UseStartup<Startup>()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseWebRoot("Pics")
|
||||
.UseSerilog()
|
||||
.Build();
|
||||
|
||||
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
||||
{
|
||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
||||
return new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.Enrich.WithProperty("ApplicationContext", Program.AppName)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl)
|
||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl)
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.CreateLogger();
|
||||
}
|
||||
|
||||
(int httpPort, int grpcPort) GetDefinedPorts(IConfiguration config)
|
||||
{
|
||||
var grpcPort = config.GetValue("GRPC_PORT", 81);
|
||||
var port = config.GetValue("PORT", 80);
|
||||
return (port, grpcPort);
|
||||
}
|
||||
|
||||
IConfiguration GetConfiguration()
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
var config = builder.Build();
|
||||
|
||||
if (config.GetValue<bool>("UseVault", false))
|
||||
{
|
||||
builder.AddAzureKeyVault(
|
||||
$"https://{config["Vault:Name"]}.vault.azure.net/",
|
||||
config["Vault:ClientId"],
|
||||
config["Vault:ClientSecret"]);
|
||||
}
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static string Namespace = typeof(Startup).Namespace;
|
||||
public static string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user