首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >API网关Ocelot .Net Core6.1安装

API网关Ocelot .Net Core6.1安装
EN

Stack Overflow用户
提问于 2022-02-25 10:31:48
回答 2查看 4.6K关注 0票数 0

.Net 6已经删除了启动类,我无法找到如何在新的.Net 6结构中配置Ocelot。我找到了两种方法

代码语言:javascript
复制
 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

请告诉我

EN

回答 2

Stack Overflow用户

发布于 2022-02-28 02:20:07

在项目中添加名为ocelot.json的json文件。

然后在Program.cs中进行这样的配置

代码语言:javascript
复制
IConfiguration configuration = new ConfigurationBuilder()
                            .AddJsonFile("ocelot.json")
                            .Build();

var builder = WebApplication.CreateBuilder(args);
//.....
builder.Services.AddOcelot(configuration);

var app = builder.Build();

//........
app.UseOcelot();

//......
票数 5
EN

Stack Overflow用户

发布于 2022-05-10 01:02:51

您需要从您的program.cs中直接声明,您需要在bulder.configuration中添加Ocelot文件,而不是在服务中添加Ocelot引用,最后启动intance app.Ocelot().wait();

这里有一个例子,希望能有所帮助。

代码语言:javascript
复制
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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71264496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档