mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 20:32:49 +08:00
54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using System;
|
|
using CacheManager.Core;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Ocelot.DependencyInjection;
|
|
using Ocelot.Middleware;
|
|
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
|
|
|
|
namespace Ocelot.ManualTest
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IHostingEnvironment env)
|
|
{
|
|
var builder = new ConfigurationBuilder()
|
|
.SetBasePath(env.ContentRootPath)
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
|
.AddJsonFile("configuration.json")
|
|
.AddEnvironmentVariables();
|
|
|
|
Configuration = builder.Build();
|
|
}
|
|
|
|
public IConfigurationRoot Configuration { get; }
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
Action<ConfigurationBuilderCachePart> settings = (x) =>
|
|
{
|
|
x.WithMicrosoftLogging(log =>
|
|
{
|
|
log.AddConsole(LogLevel.Debug);
|
|
})
|
|
.WithDictionaryHandle();
|
|
};
|
|
services.AddMemoryCache();
|
|
services.AddOcelotOutputCaching(settings);
|
|
services.AddOcelotFileConfiguration(Configuration);
|
|
services.AddOcelot();
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
{
|
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
|
|
|
app.UseOcelot();
|
|
}
|
|
}
|
|
}
|