|
1 |
| -using Microsoft.AspNetCore; |
2 | 1 | using Microsoft.AspNetCore.Hosting;
|
3 | 2 | using Microsoft.Extensions.Configuration;
|
| 3 | +using Microsoft.Extensions.Hosting; |
| 4 | +using Microsoft.Extensions.Logging; |
| 5 | +using Ocelot.Cache.CacheManager; |
| 6 | +using Ocelot.DependencyInjection; |
| 7 | +using Ocelot.Middleware; |
| 8 | +using Ocelot.Provider.Polly; |
4 | 9 | using System.IO;
|
5 | 10 |
|
6 |
| -namespace Exchange.Rates.Gateway; |
7 |
| - |
8 |
| -public class Program |
9 |
| -{ |
10 |
| - public static void Main(string[] args) |
| 11 | +IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args) |
| 12 | + .UseContentRoot(Directory.GetCurrentDirectory()) |
| 13 | + .ConfigureWebHostDefaults(webBuilder => |
11 | 14 | {
|
12 |
| - BuildWebHost(args).Run(); |
13 |
| - } |
14 |
| - |
15 |
| - public static IWebHost BuildWebHost(string[] args) => |
16 |
| - WebHost.CreateDefaultBuilder(args) |
17 |
| - .UseKestrel() |
18 |
| - .UseContentRoot(Directory.GetCurrentDirectory()) |
19 |
| - .ConfigureAppConfiguration((hostingContext, config) => |
20 |
| - { |
21 |
| - config |
22 |
| - .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath) |
23 |
| - .AddJsonFile("appsettings.json", true, true) |
24 |
| - .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true) |
25 |
| - .AddJsonFile("ocelot.json", optional: false, reloadOnChange: false) |
26 |
| - .AddJsonFile($"ocelot.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true) |
27 |
| - .AddEnvironmentVariables(); |
28 |
| - }) |
29 |
| - .UseStartup<Startup>() |
30 |
| - .Build(); |
31 |
| -} |
| 15 | + webBuilder.ConfigureServices(services => |
| 16 | + services |
| 17 | + .AddOcelot() |
| 18 | + .AddCacheManager(x => |
| 19 | + { |
| 20 | + x.WithDictionaryHandle(); |
| 21 | + }) |
| 22 | + .AddPolly()); |
| 23 | + webBuilder.Configure(app => |
| 24 | + app.UseOcelot().Wait()) |
| 25 | + .ConfigureAppConfiguration((hostingContext, config) => |
| 26 | + { |
| 27 | + config |
| 28 | + .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath) |
| 29 | + .AddJsonFile("appsettings.json", false, true) |
| 30 | + .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true) |
| 31 | + .AddJsonFile("ocelot.json", false, true) |
| 32 | + .AddJsonFile($"ocelot.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true) |
| 33 | + .AddEnvironmentVariables(); |
| 34 | + }) |
| 35 | + .ConfigureLogging((builderContext, logging) => |
| 36 | + { |
| 37 | + logging.ClearProviders(); |
| 38 | + logging.AddConsole(); |
| 39 | + logging.AddDebug(); |
| 40 | + }); |
| 41 | + }); |
32 | 42 |
|
| 43 | +IHost host = hostBuilder.Build(); |
| 44 | +await host.RunAsync(); |
0 commit comments