Code Re-factorings and formatted in web Aggregator BFF projects

This commit is contained in:
Rafsanul Hasan 2018-09-09 04:41:45 +06:00
parent 0bc2a29b38
commit 80eb943d78
No known key found for this signature in database
GPG Key ID: FC57FD2D87BE60DD
26 changed files with 810 additions and 854 deletions

View File

@ -30,5 +30,4 @@
"RequestIdKey": "OcRequestId", "RequestIdKey": "OcRequestId",
"AdministrationPath": "/administration" "AdministrationPath": "/administration"
} }
} }

View File

@ -31,4 +31,3 @@
"AdministrationPath": "/administration" "AdministrationPath": "/administration"
} }
} }

View File

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config
{ {

View File

@ -1,8 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers
{ {

View File

@ -1,9 +1,6 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services; using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Controllers

View File

@ -1,9 +1,4 @@
using System; namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
{ {
public class AddBasketItemRequest public class AddBasketItemRequest
{ {

View File

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
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
{ {

View File

@ -1,9 +1,4 @@
using System; namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
{ {
public class CatalogItem public class CatalogItem
{ {

View File

@ -1,7 +1,5 @@
using System; using System.Collections.Generic;
using System.Collections.Generic; using DateTime = System.DateTime;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
{ {

View File

@ -1,9 +1,4 @@
using System; namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models
{ {
public class OrderItemData public class OrderItemData
{ {

View File

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
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
{ {

View File

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
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
{ {

View File

@ -1,21 +1,14 @@
using System; using static Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions;
using System.Collections.Generic; using static Microsoft.AspNetCore.Hosting.WebHostExtensions;
using System.IO; using IWebHost = Microsoft.AspNetCore.Hosting.IWebHost;
using System.Linq; using WebHost = Microsoft.AspNetCore.WebHost;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
{ {
public class Program public class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ => BuildWebHost(args).Run();
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) => public static IWebHost BuildWebHost(string[] args) =>
WebHost WebHost
@ -23,7 +16,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
.ConfigureAppConfiguration(cb => .ConfigureAppConfiguration(cb =>
{ {
var sources = cb.Sources; var sources = cb.Sources;
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource() sources.Insert(3, new Extensions.Configuration.Json.JsonConfigurationSource()
{ {
Optional = true, Optional = true,
Path = "appsettings.localhost.json", Path = "appsettings.localhost.json",

View File

@ -1,13 +1,16 @@
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config; using Microsoft.Extensions.Logging;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.Net.Http;
using System.Threading.Tasks; 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 namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{ {
using BasketData = Models.BasketData;
using BasketOperations = Config.UrlsConfig.BasketOperations;
using UrlsConfig = Config.UrlsConfig;
public class BasketService : IBasketService public class BasketService : IBasketService
{ {
@ -15,7 +18,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
private readonly ILogger<BasketService> _logger; private readonly ILogger<BasketService> _logger;
private readonly UrlsConfig _urls; 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; _apiClient = httpClient;
_logger = logger; _logger = logger;
@ -24,7 +27,7 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
public async Task<BasketData> GetById(string id) 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; var basket = !string.IsNullOrEmpty(data) ? JsonConvert.DeserializeObject<BasketData>(data) : null;
return basket; 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 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);
} }
} }
} }

View File

@ -1,14 +1,15 @@
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config; using Microsoft.Extensions.Logging;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using HttpClient = System.Net.Http.HttpClient;
using JsonConvert = Newtonsoft.Json.JsonConvert;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{ {
using CatalogItem = Models.CatalogItem;
using UrlsConfig = Config.UrlsConfig;
public class CatalogService : ICatalogService public class CatalogService : ICatalogService
{ {

View File

@ -1,11 +1,9 @@
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models; using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{ {
using BasketData = Models.BasketData;
public interface IBasketService public interface IBasketService
{ {
Task<BasketData> GetById(string id); Task<BasketData> GetById(string id);

View File

@ -1,11 +1,10 @@
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models; using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{ {
using CatalogItem = Models.CatalogItem;
public interface ICatalogService public interface ICatalogService
{ {
Task<CatalogItem> GetCatalogItem(int id); Task<CatalogItem> GetCatalogItem(int id);

View File

@ -1,11 +1,10 @@
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models; using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{ {
using BasketData = Models.BasketData;
using OrderData = Models.OrderData;
public interface IOrderApiClient public interface IOrderApiClient
{ {
Task<OrderData> GetOrderDraftFromBasket(BasketData basket); Task<OrderData> GetOrderDraftFromBasket(BasketData basket);

View File

@ -1,13 +1,16 @@
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config; using Microsoft.Extensions.Logging;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.Net.Http;
using System.Threading.Tasks; 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 namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{ {
using BasketData = Models.BasketData;
using OrderData = Models.OrderData;
using UrlsConfig = Config.UrlsConfig;
public class OrderApiClient : IOrderApiClient public class OrderApiClient : IOrderApiClient
{ {

View File

@ -11,7 +11,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Polly; using Polly;
using Polly.Extensions.Http; using Polly.Extensions.Http;
using Polly.Timeout;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -22,17 +21,16 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
{ {
public class Startup public class Startup
{ {
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration) =>
{
Configuration = configuration; Configuration = configuration;
}
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddCustomMvc(Configuration) services
.AddCustomMvc(Configuration)
.AddCustomAuthentication(Configuration) .AddCustomAuthentication(Configuration)
.AddApplicationServices(); .AddApplicationServices();
} }
@ -86,13 +84,15 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
options.Audience = "webshoppingagg"; options.Audience = "webshoppingagg";
options.Events = new JwtBearerEvents() options.Events = new JwtBearerEvents()
{ {
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
OnAuthenticationFailed = async ctx => 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 => 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 => services.AddCors(options =>
{ {
options.AddPolicy("CorsPolicy", options
builder => builder.AllowAnyOrigin() .AddPolicy(
"CorsPolicy",
builder =>
builder
.AllowAnyOrigin()
.AllowAnyMethod() .AllowAnyMethod()
.AllowAnyHeader() .AllowAnyHeader()
.AllowCredentials()); .AllowCredentials());
@ -169,19 +173,14 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator
return services; return services;
} }
static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy() static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy() =>
{ HttpPolicyExtensions
return HttpPolicyExtensions
.HandleTransientHttpError() .HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound) .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))); .WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
}
static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy() static IAsyncPolicy<HttpResponseMessage> GetCircuitBreakerPolicy()
{ => HttpPolicyExtensions
return HttpPolicyExtensions
.HandleTransientHttpError() .HandleTransientHttpError()
.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30)); .CircuitBreakerAsync(5, TimeSpan.FromSeconds(30));
} }
}
} }

View File

@ -126,5 +126,4 @@
"RequestIdKey": "OcRequestId", "RequestIdKey": "OcRequestId",
"AdministrationPath": "/administration" "AdministrationPath": "/administration"
} }
} }