对于 ASP.NET Core 项目,我们可以参考这个 example code。你需要做以下步骤。
dotnet add package <todo-shenyu-asp.net-core package>
Startup.ConfigureServices
中加入 ShenyuRegister
service。public void ConfigureServices(IServiceCollection services) { ... services.AddShenyuRegister(this.Configuration); ... }
appsettings.json
中配置 http 信息。{ "Shenyu": { "Register": { "RegisterType": "http", "ServerList": "http://localhost:9095", "Props": { // your admin user name "UserName": "admin", // your admin password "Password": "123456" } }, "Client": { "AppName": "dotnet-example", "ContextPath": "/dotnet", "IsFull": false, "ClientType": "http" } } }
当运行 ASP.NET Core 项目时,默认只能通过 localhost
访问。想要允许 ip 访问,需要设置下 ASPNETCORE_URLS
环境变量。
export ASPNETCORE_URLS=http://+:5000
# build project dotnet build --configuration Release # start project cd examples/AspNetCoreExample/bin/Release/netcoreapp3.1 dotnet AspNetCoreExample.dll
至此,你已经完成所有的步骤,可以进入 shenyu-admin
页面看到这些 API 已经注册到 ShenYu.