Code Re-factorings and formatted in web Aggregator BFF projects
This commit is contained in:
parent
0bc2a29b38
commit
80eb943d78
@ -30,5 +30,4 @@
|
||||
"RequestIdKey": "OcRequestId",
|
||||
"AdministrationPath": "/administration"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,4 +31,3 @@
|
||||
"AdministrationPath": "/administration"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config
|
||||
{
|
||||
|
@ -1,8 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
{
|
||||
|
@ -1,9 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
public class AddBasketItemRequest
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
public class CatalogItem
|
||||
{
|
||||
|
@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using DateTime = System.DateTime;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
public class OrderItemData
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
|
||||
{
|
||||
|
@ -1,21 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions;
|
||||
using static Microsoft.AspNetCore.Hosting.WebHostExtensions;
|
||||
using IWebHost = Microsoft.AspNetCore.Hosting.IWebHost;
|
||||
using WebHost = Microsoft.AspNetCore.WebHost;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildWebHost(args).Run();
|
||||
}
|
||||
=> BuildWebHost(args).Run();
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost
|
||||
@ -23,7 +16,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
.ConfigureAppConfiguration(cb =>
|
||||
{
|
||||
var sources = cb.Sources;
|
||||
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource()
|
||||
sources.Insert(3, new Extensions.Configuration.Json.JsonConfigurationSource()
|
||||
{
|
||||
Optional = true,
|
||||
Path = "appsettings.localhost.json",
|
||||
|
@ -1,13 +1,16 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using HttpClient = System.Net.Http.HttpClient;
|
||||
using JsonConvert = Newtonsoft.Json.JsonConvert;
|
||||
using StringContent = System.Net.Http.StringContent;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
using BasketData = Models.BasketData;
|
||||
using BasketOperations = Config.UrlsConfig.BasketOperations;
|
||||
using UrlsConfig = Config.UrlsConfig;
|
||||
|
||||
public class BasketService : IBasketService
|
||||
{
|
||||
|
||||
@ -15,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
private readonly ILogger<BasketService> _logger;
|
||||
private readonly UrlsConfig _urls;
|
||||
|
||||
public BasketService(HttpClient httpClient,ILogger<BasketService> logger, IOptions<UrlsConfig> config)
|
||||
public BasketService(HttpClient httpClient, ILogger<BasketService> logger, IOptions<UrlsConfig> config)
|
||||
{
|
||||
_apiClient = httpClient;
|
||||
_logger = logger;
|
||||
@ -24,7 +27,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
|
||||
public async Task<BasketData> GetById(string id)
|
||||
{
|
||||
var data = await _apiClient.GetStringAsync(_urls.Basket + UrlsConfig.BasketOperations.GetItemById(id));
|
||||
var data = await _apiClient.GetStringAsync(_urls.Basket + BasketOperations.GetItemById(id));
|
||||
var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null;
|
||||
return basket;
|
||||
}
|
||||
@ -33,7 +36,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
var basketContent = new StringContent(JsonConvert.SerializeObject(currentBasket), System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
var data = await _apiClient.PostAsync(_urls.Basket + UrlsConfig.BasketOperations.UpdateBasket(), basketContent);
|
||||
var data = await _apiClient.PostAsync(_urls.Basket + BasketOperations.UpdateBasket(), basketContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using HttpClient = System.Net.Http.HttpClient;
|
||||
using JsonConvert = Newtonsoft.Json.JsonConvert;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
using CatalogItem = Models.CatalogItem;
|
||||
using UrlsConfig = Config.UrlsConfig;
|
||||
|
||||
public class CatalogService : ICatalogService
|
||||
{
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
using BasketData = Models.BasketData;
|
||||
|
||||
public interface IBasketService
|
||||
{
|
||||
Task<BasketData> GetById(string id);
|
||||
|
@ -1,11 +1,10 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
using CatalogItem = Models.CatalogItem;
|
||||
|
||||
public interface ICatalogService
|
||||
{
|
||||
Task<CatalogItem> GetCatalogItem(int id);
|
||||
|
@ -1,11 +1,10 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
using BasketData = Models.BasketData;
|
||||
using OrderData = Models.OrderData;
|
||||
|
||||
public interface IOrderApiClient
|
||||
{
|
||||
Task<OrderData> GetOrderDraftFromBasket(BasketData basket);
|
||||
|
@ -1,13 +1,16 @@
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
|
||||
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using HttpClient = System.Net.Http.HttpClient;
|
||||
using JsonConvert = Newtonsoft.Json.JsonConvert;
|
||||
using StringContent = System.Net.Http.StringContent;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
|
||||
{
|
||||
using BasketData = Models.BasketData;
|
||||
using OrderData = Models.OrderData;
|
||||
using UrlsConfig = Config.UrlsConfig;
|
||||
|
||||
public class OrderApiClient : IOrderApiClient
|
||||
{
|
||||
|
||||
|
@ -11,7 +11,6 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Polly;
|
||||
using Polly.Extensions.Http;
|
||||
using Polly.Timeout;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -22,17 +21,16 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
public Startup(IConfiguration configuration) =>
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddCustomMvc(Configuration)
|
||||
services
|
||||
.AddCustomMvc(Configuration)
|
||||
.AddCustomAuthentication(Configuration)
|
||||
.AddApplicationServices();
|
||||
}
|
||||
@ -86,13 +84,15 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
options.Audience = "webshoppingagg";
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||
OnAuthenticationFailed = async ctx =>
|
||||
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||
{
|
||||
int i = 0;
|
||||
},
|
||||
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||
OnTokenValidated = async ctx =>
|
||||
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||
{
|
||||
int i = 0;
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -134,8 +134,12 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("CorsPolicy",
|
||||
builder => builder.AllowAnyOrigin()
|
||||
options
|
||||
.AddPolicy(
|
||||
"CorsPolicy",
|
||||
builder =>
|
||||
builder
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials());
|
||||
@ -169,19 +173,14 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
|
||||
return services;
|
||||
}
|
||||
|
||||
static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
|
||||
{
|
||||
return HttpPolicyExtensions
|
||||
static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy() =>
|
||||
HttpPolicyExtensions
|
||||
.HandleTransientHttpError()
|
||||
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
||||
|
||||
}
|
||||
static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()
|
||||
{
|
||||
return HttpPolicyExtensions
|
||||
=> HttpPolicyExtensions
|
||||
.HandleTransientHttpError()
|
||||
.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,5 +126,4 @@
|
||||
"RequestIdKey": "OcRequestId",
|
||||
"AdministrationPath": "/administration"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user