Devprime 9

Welcome to the Devprime 9 update guide! Here, you’ll find everything you need to transition from version 8 to version 9 efficiently by leveraging the power of the .NET 9 SDK.

This guide covers the essentials for upgrading from Devprime Platform version 8 to version 9 by leveraging the .NET 9 SDK. We’ve included detailed instructions on dockerfile changes, methods, settings, and more.


What’s New: Microsoft OpenAPI / Swagger / Scalar

.NET 9 introduced the Microsoft.AspNetCore.OpenApi library, which changes the traditional approach to documenting APIs. Now, it is possible to use tools such as Swagger and Scalar directly with this new library.

Available Tools

  • Microsoft.AspNetCore.OpenApi
  • Swashbuckle.AspNetCore.Swagger
  • Scalar.AspNetCore

Updates to Methods in File App.cs

The table below highlights the changes in Devprime’s methods:

Scope Method Description
Builder AddOpenApi New Method to Add OpenApi
Builder AddSwagger Renamed to AddDevPrimeSwagger
Builder AddScalar New method to add Scalar
App UseOpenApi New Method to Configure OpenApi
App UseSwagger Renamed to UseDevPrimeSwagger
App UseScalar New method to configure Scalar

Updates in appsettings.json

Add or revise the keys below:

Key Description Status
EnableSwagger Enable Swagger Documentation Existing
EnableScalar Enable Scalar Documentation New
EnableOpenApi Enable OpenApi New
GetNotFound Enable customization for HTTP 404 New

Configuration Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
"DevPrime_Web": {
    "Url": "https://localhost:5001;http://localhost:5000",
    "Enable": "true",
    "EnableOpenApi": "true",
    "EnableSwagger": "true",    
    "EnableScalar": "true",
    "PostSuccess": "201",
    "PostFailure": "500",
    "GetSuccess": "200",
    "GetNotFound": "404",
    "GetFailure": "500",
    "PatchSuccess": "200",
    "PatchFailure": "500",
    "PutSuccess": "200",
    "PutFailure": "500",
    "DeleteSuccess": "200",
    "DeleteFailure": "500",
    "EnableWebLegacy": "false",
    "EnableStaticFiles": "true",
    "ShowHttpRequests": "false",
    "ShowBadRequestDetails": "false"
  },

Step by Step for Update

1. Environment Preparation

a. Install .NET SDK 9
Download .NET SDK

b. Update Devprime CLI

1
dotnet tool update --global Devprime.cli

c. Authenticate in the CLI

1
dp auth

2. Project Updates

a. Update Files .csproj

Modify TargetFramework to net9.0 using Visual Studio Code. Open the project folder in VS Code and in the Edit > Replace in Files menu, locate the items below and perform the replacement.

Project Updates

b. Upgrade Devprime’s Stack

Updated the Devprime components to version 9.0 in the .csproj file and the new License key in the appsettings.json file.

Run the command in your project folder:

1
dp stack

c. Update the dockerfile

Update the references to .NET 9, change the dockerfile to use the docker image based on the .NET SDK 9. You need to locate the ASP.NET and then the SDK to perform the update.

  • Open Visual Studio Code in your project folder
1
code dockerfile
  • Locate the aspnet reference and change it to the example:
1
FROM mcr.microsoft.com/dotnet/aspnet:9.0.0-noble AS base
  • Locate the sdk reference and change to the example:
1
FROM mcr.microsoft.com/dotnet/sdk:9.0.100-noble AS build

c. Update App.cs

With the introduction of the new methods (AddOpenApi, AddSwagger, AddScalar, and their Use* equivalents), configure the App.cs file to utilize the desired resources. Here are the detailed guidelines:

Open through Visual Studio Code in your project folder

1
code src/App/App.cs

Step 1: On the block builder
The example below shows the addition of the OpenAPI, Swagger, and Scalar services. You can use
the Swagger and Scalar together.

1
2
3
DpApp.AddOpenApi(builder.Services); // Add OpenAPI Services
DpApp.AddSwagger(builder.Services); // Add Swagger Services
DpApp.AddScalar(builder.Services);  // Add Scalar Services

Step 2: On the block app
Configure the services in the app tile. The recommended order is UseOpenApi, followed by UseSwagger or UseScalar.

1
2
3
DpApp.UseOpenApi(app); // Enable OpenApi
DpApp.UseSwagger(app); // Enable Swagger
DpApp.UseScalar(app);  // Enable Scalar

Step 3: Full file example App.cs
The App.cs can be configured to use OpenAPI, Swagger, and Scalar simultaneously as per
the example below from the microservice order.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMvc(o =>
{
    o.EnableEndpointRouting = false;
});

builder.Services.AddScoped<IExtensions, Extensions>();
builder.Services.AddScoped<IEventStream, EventStream>();
builder.Services.AddScoped<IEventHandler, Application.EventHandlers.EventHandler>();

await new DpApp(builder).Run("order", (app) =>
{
    app.UseRouting();
    
    app.UseAuthentication(); // Enable Authentication

    DpApp.UseOpenApi(app); // Enable OpenApi
    DpApp.UseSwagger(app); // Enable Swagger
    DpApp.UseScalar(app);  // Enable Scalar 


    app.UseAuthorization(); // Enable Authorization

    app.MapControllerRoute(
       name: "default",
       pattern: "{controller=Home}/{action=Index}/{id?}");
}, (builder) =>
{
    DpApp.AddDevPrime(builder.Services); // Enable Foundation

    DpApp.AddOpenApi(builder.Services); // Add OpenAPI Services
    DpApp.AddSwagger(builder.Services); // Add Swagger Services
    DpApp.AddScalar(builder.Services);  // Add Scalar Services

    DpApp.AddDevPrimeSecurity(builder.Services); // Add Security Services
});

Observations:

  • Market trends: The use of Scalar is becoming popular and can replace Swagger in many cases. You can set up both initially and disable one of them as needed.
  • Guaranteed compatibility: In case you don’t make any changes to the App.cs file, the default behavior will not be broken, but it is recommended to adopt the new methods to enjoy all the benefits.

d. Urls do OpenApi / Swagger / Scalar

Devprime will, by default, enable default URLs for the OpenApi, Swagger, and Scalar services, if enabled, as per the addresses below. These addresses will also vary depending on the local TCP port used in your microservice and the name of your project.

Example: For a project named order running on TCP port 5001:

Service URL
OpenApi https://localhost:5001/openapi/order/1.0.0.0.json
Swagger https://localhost:5001/swagger/index.html
Scalar https://localhost:5001/scalar/order

3. Web Interface Update (Optional)

Edit the index.cshtml file to include links to Swagger, Scalar, and OpenAPI:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
@page
@model DevPrime.Web.IndexModel
@{
    ViewData["Title"] = DevPrime.Stack.Foundation.Setup.AppName;
}

<div style='text-align:center;padding:10px;margin:10px;color:#512da8'>
    <h1>Welcome to @DevPrime.Stack.Foundation.Setup.AppName! </h1>
    <h2>Powered by Devprime</h2>
    <p>Microservice Id : @DevPrime.Stack.Foundation.Setup.AppID</p>
   
    <p>Try: 
        [<a href="~/openapi/@(DevPrime.Stack.Foundation.Setup.AppName)/
        @(DevPrime.Stack.Foundation.Setup.AppVersion).json">OpenApi</a>]
        [<a href='~/swagger/index.html'>Swagger</a>]
        [<a href="~/scalar/@DevPrime.Stack.Foundation.Setup.AppName">Scalar</a>]
    </p>
</div>

4. Updating yaml settings in Kubernetes (Optional)

It’s important to remember that during this roadmap we’ve included new configuration buzzwords and you can manually change and/or use the Devprime CLI exporter to export the updated configuration:

Important Checklist
a) New configuration parameters: (EnableSwagger, EnableScalar, EnableOpenApi, GetNotFound).
b) New License key that has been applied in your appsettings.json and needs to be updated in the production yaml.

For a complete example, run the command in the project folder:

1
dp export Kubernetes

Conclusion

By following this guide, your application will be ready to use what’s new in Devprime 9 and .NET 9. For questions, please contact technical support.


Last modified February 27, 2025 (2499051c)