Aktualisieren Sie das Projekt auf .NET 9.0 und verbessern Sie die API-Unterstützung
- Zielen Sie nur auf .NET 9.0 in `EnvelopeGenerator.GeneratorAPI.csproj`. - Fügen Sie das Paket `AspNetCore.Scalar` hinzu und aktualisieren Sie `Microsoft.AspNetCore.OpenApi` auf Version 9.0.3. - Scalar.AspNetCore„ in die Datei “Program.cs" einbinden. - Integrieren Sie OpenAPI-Unterstützung mit `AddOpenApi()` und bilden Sie Endpunkte mit `app.MapOpenApi()` und `app.MapScalarApiReference()` ab.
This commit is contained in:
@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Globalization;
|
||||
using Scalar.AspNetCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -32,7 +33,7 @@ builder.Services.AddCors(options =>
|
||||
// Swagger
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddOpenApi();
|
||||
// DbContext
|
||||
var connStr = config.GetConnectionString("Default") ?? throw new InvalidOperationException("There is no default connection string in appsettings.json.");
|
||||
builder.Services.AddDbContext<EGDbContext>(options => options.UseSqlServer(connStr));
|
||||
@@ -66,11 +67,14 @@ builder.Services
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapOpenApi();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.MapScalarApiReference();
|
||||
}
|
||||
|
||||
// Set CORS policy
|
||||
|
||||
Reference in New Issue
Block a user