Re-factored and formatted OcelotApiGw project

This commit is contained in:
Rafsanul Hasan 2018-09-09 04:07:24 +06:00
parent 25cc0cf562
commit 4e774612ae
No known key found for this signature in database
GPG Key ID: FC57FD2D87BE60DD
2 changed files with 98 additions and 94 deletions

View File

@ -1,13 +1,10 @@
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 Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using static Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions;
using static Microsoft.AspNetCore.Hosting.WebHostExtensions;
using IWebHost = Microsoft.AspNetCore.Hosting.IWebHost;
using Path = System.IO.Path;
using WebHost = Microsoft.AspNetCore.WebHost;
namespace OcelotApiGw
{
@ -20,11 +17,12 @@ namespace OcelotApiGw
public static IWebHost BuildWebHost(string[] args)
{
IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args);
builder.ConfigureServices(s => s.AddSingleton(builder))
var builder = WebHost.CreateDefaultBuilder(args);
builder
.ConfigureServices(s => s.AddSingleton(builder))
.ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
.UseStartup<Startup>();
IWebHost host = builder.Build();
var host = builder.Build();
return host;
}
}

View File

@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CacheManager.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -29,17 +23,26 @@ namespace OcelotApiGw
var identityUrl = _cfg.GetValue<string>("IdentityUrl");
var authenticationProviderKey = "IdentityApiKey";
services.AddCors(options =>
services
.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
options
.AddPolicy(
"CorsPolicy",
builder =>
builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
.AllowCredentials()
);
});
services.AddAuthentication()
.AddJwtBearer(authenticationProviderKey, x =>
services
.AddAuthentication()
.AddJwtBearer(
authenticationProviderKey,
x =>
{
x.Authority = identityUrl;
x.RequireHttpsMetadata = false;
@ -49,18 +52,21 @@ namespace OcelotApiGw
};
x.Events = new Microsoft.AspNetCore.Authentication.JwtBearer.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;
},
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
OnMessageReceived = async ctx =>
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
{
int i = 0;
}
};
});