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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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