Backend Graph Upgrade
📆 Date: 2024-11-18
Rationale
The upgrade to .NET 9 implies some relevant changes:
- drop Swagger (whose development was left behind) for Scalar, integrating the new OpenAPI capabilities from .NET 9.
- drop MongoDB-based authentication for RDBMS-based authentication via PostgreSQL. This does not affect the system, except for the requirement to migrate user accounts from MongoDB to PostgreSQL, which is best accomplished by just recreating them in the new environment.
- refactor the API code to reflect the more modern code style already in use from past versions of .NET, removing the
Startup
class. This also allows moving most of the API app code to a new library,Cadmus.Api.Config
, thus making the API code much more streamlined.
Affected Products
⚠️ All the API libraries and apps.
Upgrade Path
Provided that you have upgraded to .NET 9 your models (if any):
- upgrade to .NET 9 (including the Dockerfile references to .NET images).
- update all packages.
-
add packages:
<PackageReference Include="Cadmus.Api.Config" Version="10.1.2" /> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" /> <PackageReference Include="Scalar.AspNetCore" Version="1.2.43" />
Update versions of these packages if newer are available.
- remove packages
AspNetCore.Identity.Mongo
andSwashbuckle.AspNetCore
. - add the
Auth
connection string toappconfig.json
under sectionConnectionStrings
:"Auth": "Server=localhost;Database={0};User Id=postgres;Password=postgres;Include Error Detail=True",
. -
in
appconfig.json
, add rate limiter configuration so that it is disabled by default:"RateLimit": { "IsDisabled": true, "PermitLimit": 100, "QueueLimit": 0, "TimeWindow": "00:01:00" },
- in
appconfig.json
, changeSeed:IndexDelay
entry toSeed:Delay
. Also change the environment variable name in Docker compose accordingly toSEED__DELAY
. - replace
Program.cs
with the code from the new API v10+ solution. The only change required refers to the name of the repository and part seeder factory providers for your project, inProgram.ConfigureAppServices
:__PRJ__RepositoryProvider
and__PRJ__PartSeederFactoryProvider
(seeStartup.ConfigureServices
). - remove
Startup.cs
. - in the API project Debug properties, change the startup route from
swagger
toscalar/v1
. - update the .NET image versions to 9 in your Dockerfile, ensuring that 8080 is the exposed port.
- in your Docker compose:
- add the environment variable to override the connection to the AUTH database:
- ensure that ASP.NET core port is set to 8080 and that the environment variable
ASPNETCORE_URLS
is properly set. - ensure that
SEED__DELAY
(renamed fromSEED__INDEXDELAY
) is set if you are going to seed mock items, so that there is a pause before the API starts using the database service when this is still starting.
Example:
cadmus-vela-api:
image: vedph2020/cadmus-vela-api:4.0.1
container_name: cadmus-vela-api
ports:
- 5080:8080
depends_on:
- cadmus-vela-mongo
- cadmus-vela-pgsql
environment:
# for Windows use : as separator, for non Windows use __
# (see https://github.com/aspnet/Configuration/issues/469)
- ASPNETCORE_URLS=http://+:8080
- CONNECTIONSTRINGS__DEFAULT=mongodb://cadmus-vela-mongo:27017/{0}
- CONNECTIONSTRINGS__AUTH=Server=cadmus-vela-pgsql;port=5432;Database={0};User Id=postgres;Password=postgres;Include Error Detail=True
- CONNECTIONSTRINGS__INDEX=Server=cadmus-vela-pgsql;port=5432;Database={0};User Id=postgres;Password=postgres;Include Error Detail=True
- SERILOG__CONNECTIONSTRING=mongodb://cadmus-vela-mongo:27017/{0}-log
- STOCKUSERS__0__PASSWORD=P4ss-W0rd!
- SEED__DELAY=20
- MESSAGING__APIROOTURL=http://cadmusapi.azurewebsites.net
- MESSAGING__APPROOTURL=http://cadmusapi.com/
- MESSAGING__SUPPORTEMAIL=support@cadmus.com
networks:
- cadmus-vela-network
If using bibliography API, remember to upgrade it to version 7+, because this shares the new PostgreSQL-based auth database.