ParisaJahanian / Ocelot.Provider.SqlServer

With this package you can store the Ocelot routes in sql server instead of json file and add route dynamically. Ocelot.Provider.SqlServer is designed to work with ASP.NET and is currently on net6.0.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ocelot.Provider.SqlServer

Getting Started

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.

.NET 6.0

1. Install NuGet package

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/

2. Register Ocelot.Provider.SqlServer

in Program.cs

> builder.Services.AddOcelot()
    .AddSqlServerProvider(options =>
    {
        options.DbConnectionStrings = builder.Configuration.GetConnectionString("SqlServerDb");
        options.MigrationsAssembly = Assembly.GetExecutingAssembly().FullName;
    });

3. Add Middleware

> app.UseOcelotWithSqlServerProvider().Wait();

4. Add SqlServer connection string in appsettings.json

"ConnectionStrings": {
    "SqlServerDb": "Server=(localdb)\\mssqllocaldb;Database=OcelotDb;Trusted_Connection=True;MultipleActiveResultSets=true"
  },

5. Database Migration

First:

Set your apigateway project as startup project

Second:

Run following ef command in Package Manager Console(with visual studio)

add migration

> Add-Migration InitDb

update database

> Update-Database

Now check your database, you have two tables:

OcelotRoutes --> add your route to this table

OcelotGlobalConfigurations

The source of a project that used Ocelot.Provider.SqlServer is also included.

Sample for ApiGateway

Sample for Api

Please share your thoughts, feedback or suggestions. I would love to hear from you and I response to every single issue or message.

About

With this package you can store the Ocelot routes in sql server instead of json file and add route dynamically. Ocelot.Provider.SqlServer is designed to work with ASP.NET and is currently on net6.0.


Languages

Language:C# 97.5%Language:Dockerfile 2.5%