Ocelot.Provider.SqlServer is designed to work with ASP.NET and is currently on net6.0.
With this package you can store the Ocelot routes in sql server instead of Json file and add route dynamically.
Install Ocelot.Provider.SqlServer using nuget. You will need to create a net6.0 project and bring the package into it. Then follow the Startup below and Configuration sections to get up and running.
> Install-Package Ocelot.Provicer.SqlServer
Nuget Address:
https://www.nuget.org/packages/Ocelot.Provider.SqlServer/
> builder.Services.AddOcelot()
.AddSqlServerProvider(options =>
{
options.DbConnectionStrings = builder.Configuration.GetConnectionString("SqlServerDb");
options.MigrationsAssembly = Assembly.GetExecutingAssembly().FullName;
});
> app.UseOcelotWithSqlServerProvider().Wait();
"ConnectionStrings": {
"SqlServerDb": "Server=(localdb)\\mssqllocaldb;Database=OcelotDb;Trusted_Connection=True;MultipleActiveResultSets=true"
},
Set your apigateway project as startup project
Run following ef command in Package Manager Console(with visual studio)
> Add-Migration InitDb
> Update-Database
Please share your thoughts, feedback or suggestions. I would love to hear from you and I response to every single issue or message.