ASP.NET est un framework Web open source, créé par Microsoft, pour créer des applications et des services Web modernes avec .NET. ASP.NET est multiplateforme et fonctionne sous Windows, Linux, macOS et Docker.
plus : https://dotnet.microsoft.com/en-us/learn/aspnet/what-is-aspnet
Créer un projet de solution
dotnet new sln -n Tutorial-ApiCréer un projet API Web ASP.NET
dotnet new webapi -o ApiCréer un projet XUnit
dotnet new xunit -o Xunit.TestsAjouter des projets à la solution
dotnet sln add .Tutorial.ApiTutorial.Api.csproj
dotnet sln add .XUnit.TestsXUnit.Tests.csprojAjouter un projet de référence dans le projet xunit
dotnet add . /XUnit.Tests/XUnit.Tests.csproj reference .Tutorial.ApiTutorial.Api.csproj Ajouter la dépendance MongoDB Driver dans le projet
dotnet add package MongoDB.Driver --version 2.18.0Mongocoque
Install mongo-shell
https://www.mongodb.com/docs/mongodb-shell/install/
> mongod --dbpath < data_directory_path >
> show dbs
> use tutorialdb
> db.createCollection( ' tutorials ' )
> db.tutorials.insertMany([{ " title " : " Design Patterns " , " description " : " " , " published " : false}])
> db.tutorials.find().pretty ()
dotnet run --project . /Tutorial.Api/Swagger : https://localhost:7272/swagger

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run#examples
GET /api/tutoriels
Réponse
[
{
"id" : " 63730beabd3cb05f2331be45 " ,
"title" : " hello " ,
"description" : " world " ,
"published" : null ,
"createdAt" : " 0001-01-01T00:00:00Z " ,
"updatedAt" : " 0001-01-01T00:00:00Z "
},
{
"id" : " 63732124796b18bc753e9157 " ,
"title" : " dotnet " ,
"description" : " microsoft " ,
"published" : null ,
"createdAt" : " 0001-01-01T00:00:00Z " ,
"updatedAt" : " 0001-01-01T00:00:00Z "
}
]GET /api/tutorials/{id}
Réponse
{
"id" : " 63730beabd3cb05f2331be45 " ,
"title" : " hello " ,
"description" : " world " ,
"published" : null ,
"createdAt" : " 0001-01-01T00:00:00Z " ,
"updatedAt" : " 0001-01-01T00:00:00Z "
}POST /api/tutoriels
Corps de la demande
{
"title" : " string " ,
"description" : " string " ,
}Corps de réponse
{
"code" : " 200 " ,
"message" : " Inserted a single document Success "
}SUPPRIMER /api/tutoriels
Corps de réponse
{
"code" : " 200 " ,
"message" : " All deleted "
}SUPPRIMER /api/tutorials/{id}
Corps de réponse
{
"code" : " 200 " ,
"message" : " Deleted id 63730beabd3cb05f2331be45 "
}PUT /api/tutorials/{id}
Corps de la demande
{
"id" : " 63730beabd3cb05f2331be45 " ,
"title" : " hello " ,
"description" : " world " ,
"published" : true
}Corps de réponse
{
"code" : " 200 " ,
"message" : " Deleted id 63730beabd3cb05f2331be45 "
} dotnet buildRestaurer en couches distinctes
dotnet restoreCréer et publier une version
dotnet publish -c Release -o out Couverture d'exécution
dotnet test --collect:"XPlat Code Coverage"Ajouter un nuget ReportGenerator
dotnet add package ReportGenerator --version 5.1.10Outil de configuration ReportGenerator
dotnet tool install -g dotnet-reportgenerator-globaltoolplus : https://www.nuget.org/packages/ReportGenerator
reportgenerator -reports:"XUnit.TestsTestResults*coverage.cobertura.xml" -targetdir:". /coveragereport" -reporttypes:Html Variables d'environnement
| Nom de l'environnement | Valeur |
|---|---|
| TutorielDatabase__ConnectionString | mongodb://xxxxxxxxx |
| TutorielDatabase__DatabaseName | tutorieldb |
| TutorialDatabase__TutorialCollectionName | tutoriels |
https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger#aspnet-core-applications
Ajouter le package ApplicationInsights
dotnet add package Microsoft.ApplicationInsights.AspNetCore --version 2.21.0...