.Net 6已经删除了启动类,我无法找到如何在新的.Net 6结构中配置Ocelot。我找到了两种方法
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddOcelot()// 1.ocelot.json goes where?
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddOcelot(); // 2.what is the use of this请告诉我
发布于 2022-02-28 02:20:07
在项目中添加名为ocelot.json的json文件。
然后在Program.cs中进行这样的配置
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("ocelot.json")
.Build();
var builder = WebApplication.CreateBuilder(args);
//.....
builder.Services.AddOcelot(configuration);
var app = builder.Build();
//........
app.UseOcelot();
//......发布于 2022-05-10 01:02:51
您需要从您的program.cs中直接声明,您需要在bulder.configuration中添加Ocelot文件,而不是在服务中添加Ocelot引用,最后启动intance app.Ocelot().wait();
这里有一个例子,希望能有所帮助。
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("ocelot.json");
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddOcelot();
var app = builder.Build();
//if (app.Environment.IsDevelopment())
//{
app.UseSwagger();
app.UseSwaggerUI();
//}
app.UseHttpsRedirection();
app.UseOcelot().Wait();
app.UseAuthorization();
app.MapControllers();
app.Run();https://stackoverflow.com/questions/71264496
复制相似问题